QPainter not drawing the rectangle on QLabel
-
I am displaying image on q QLabel and want to draw a rectangle on it with mouse movement
Image is loaded correctly and selectionRect has correct co-ordinates. Its co-ordinates are changing with mouse move.
However, This painEvent is not painting. Could someone help me on this?
@
void XWizardPage :: paintEvent(QPaintEvent * e)
{
QImage tmp(label1->pixmap()->toImage());
QPainter painter(&tmp);
QPen paintpen(Qt::red);
paintpen.setWidth(3);painter.setPen(paintpen); painter.drawRect(selectionRect);
}
@Secondly, How can I draw multiple rectangles on my QLabel?
-
Found the mistake, I was not setting image back to the label.
Added the following line and it works more than perfect.
@ label1->setPixmap(QPixmap::fromImage(tmp));@How can I avoid the "intermediate drawings":http://tinypic.com/r/2nswhh0/8?
!http://tinypic.com/r/2nswhh0/8(Problem image)! -
[quote author="tesmai4" date="1406043994"]How can I avoid the "intermediate drawings":http://tinypic.com/r/2nswhh0/8?
!http://tinypic.com/r/2nswhh0/8(Problem image)![/quote]I guess you need to redraw the part of image that is covered by previous rectangle and then draw your new rectangle.
BTW(By The Way) If you trying to implement a selection rectangle then take a look on "QRubberBand":http://qt-project.org/doc/qt-5/qrubberband.html#details