Drawing a rectangle on the image displayed on UILable
I displayed an image on UIlabel as follow
@QImage rImg = QImage(templ->width,templ->height, QImage::Format_RGB888);
pixma = QPixmap::fromImage(rImg);
I also have a rectangle with x, y, width and height information.
How can I display the rectangle on the image?
Very easy in QML or QGraphicsView. A bit trickier with QPainter. Also not straightforward with QLabel.
You need to either blend the images and then set the result on your QLabel, or create 2 QLabels on top of each other, and place the rectangle on the one above (you also need to set the label to be transparent).
Oh, and if by rectangle you mean QRect, then you need to change that. QRect is just a mathematical abstraction (an object storing x, y, width and height), it has no graphical representation as such (hence it residing in QtCore).
Now I changed to QGraphicsView. How to draw a rectangle with a color?
General page on the framework: "link":http://qt-project.org/doc/qt-4.8/graphicsview.html.
And here is your "rectangle item":http://qt-project.org/doc/qt-4.8/qgraphicsrectitem.html.
I draw the rectangle as below.
scene2->addRect(showRect.x, showRect.y, showRect.width, showRect.height);
How to get the rectangle in color?
I think you need to use "setBrush()":http://qt-project.org/doc/qt-4.8/qabstractgraphicsshapeitem.html#setBrush method.
Well except the coding part there is one more way for graphical representation is use of 3D charting with support of HTML5, for that "Dashboard Chart":http://www.koolchart.com.