PDA

View Full Version : How can I draw with brush on QLabel?



suseway
25th October 2010, 15:44
I have QLabel on the form. I use it to show an image like this:



QString fileName = "image.jpg";
QImage image(fileName);
ui->label->setPixmap(QPixmap::fromImage(image.scaled(349,228, Qt::KeepAspectRatio, Qt::FastTransformation)));
ui->label->adjustSize();


How can I paint with brush on my QLabel with mouse? For example, i press left mouse key, then dragging, it lefts brush'es line, then the results - on the QLabel.

genjix
25th October 2010, 18:28
erm, I don't think you should be using a QLabel for that. Take a look at QPainter. QLabel is for displaying text (or an image)

suseway
25th October 2010, 19:03
erm, I don't think you should be using a QLabel for that. Take a look at QPainter. QLabel is for displaying text (or an image)

in my programm i use QLabel for displaying an image, and i want to draw on this image (QLabel) with mouse pointer. How can i do it?

wysota
25th October 2010, 21:03
Reimplement paint event and mouse events for the widget.

Lykurg
25th October 2010, 21:13
What is the benefit of creating a QImage and then immediately converting it to a QPixmap?

For painting: Reimp all needed mouse event handlers and then either using QPainter and draw an the QPixmap or store all lines etc. call update() and do the drawings at the paint event.

EDIT: Just found out, that my browser has a refresh button. Maybe I should use it from time to time...