First, preface
This article mainly uses the Knowledge 1, the Qtableview control proxy delegate, 2, the color progress bar setting, 3, OpenCV's Mat data display question
This article mainly realizes the function as follows: Uses the Qgraphicsview control to display the classification chart, and realizes the related enlargement, the reduction, the translation and so on, carries on the delegate display to the Qtableview; uses PS to draw the progress bar, adds the resource file as the color progress bar Qgraphicsview show OpenCV mat data; Double-click Qtableview to set the custom color.
Second, Qtableview control delegate
Using the Qitemdelegate class, implement the following function, add a background color to the column of the control, the code is as follows:
1#include"colorDegete.h"2#include <QPixmap>3#include <QApplication>4#include <QRect>5#include <QVector>6#include <QDebug>7 8 9Colordegete::colordegete (Qobject *parent)Ten : qitemdelegate (parent) One { A - } - thecolordegete::~Colordegete () - { - - } + - voidColordegete::p aint (Qpainter *painter,ConstQstyleoptionviewitem &option,ConstQmodelindex &index)Const + { AQString data =index.data (). toString (); atQstringlist List1 = Data.split (",", qstring::skipemptyparts); - intR = list1.at (0). ToInt (); - intg = list1.at (1). ToInt (); - intb = list1.at (2). ToInt (); - Qcolor Color (r,g,b); -Qrect rect =Option.rect; in Qpixmap Pixmap (Rect.width (), Rect.height ()); - Pixmap.fill (color); toQapplication::style ()Drawitempixmap (Painter,option.rect,qt::aligncenter,qpixmap (Pixmap)); +}
View Code
Third, color progress bar settings
Using PS to draw the color progress bar file, save as JPG format, and then add the resource file, using Qcombobox as icon to add the entry, the Code section is as follows:
1Qpixmap Icon1 (":/colorbar/colorbar/1.jpg");2Qpixmap Icon2 (":/colorbar/colorbar/2.jpg");3Qpixmap Icon3 (":/colorbar/colorbar/3.jpg");4Qpixmap Icon4 (":/colorbar/colorbar/4.jpg");5Qpixmap Icon5 (":/colorbar/colorbar/5.jpg");6 7Ui->colorcombobox->additem (Qicon (Icon1),"");8Ui->colorcombobox->additem (Qicon (Icon2),"");9Ui->colorcombobox->additem (Qicon (Icon3),"");TenUi->colorcombobox->additem (Qicon (Icon4),""); OneUi->colorcombobox->additem (Qicon (ICON5),"");
View Code
Iv. using Qgraphicsview to display OPENCV's mat image
The specific code is as follows:
1 BOOLclassifiedmapview::showclassifiedmap (cv::mat img)2 {3 if(Img.channels ()! =3)4 return 0;5 if(!img.iscontinuous ())6 return 0;7 8 Cv::cvtcolor (IMG,IMG,CV_BGR2RGB);9Qdebug () <Img.type ();TenQimage image = Qimage ((ConstUnsignedChar*) (Img.data), img.cols,img.rows,img.cols*img.channels (), One qimage::format_rgb888); AQgraphicsscene *tmpscene =NewQgraphicsscene ( This); -Qgraphicspixmapitem *imgitem =NewQgraphicspixmapitem (qpixmap::fromimage (image)); -Tmpscene->AddItem (imgitem); the This-Setscene (tmpscene); - return 1; - -}
View Code
V. Overall effect
6. Classification Chart Display and save