View Full Version : Drawing over QLabel
nunnu
16th September 2010, 14:57
Hi,
I have a QLabel on which I have set a pixmap of an image
QImage image(fileName);
if (image.isNull()) {
QMessageBox::information(this, tr("Image Viewer"),
tr("Cannot load %1.").arg(fileName));
return;
}
imageLabel->setPixmap(QPixmap::fromImage(image));
Now, I want to write text over this image which i have loaded into QLabel
Please tell me how to do this.
Cheers
Lykurg
16th September 2010, 15:06
You can paint on the pixmap itself (simply set a painter on it and draw) or you reimplemented the paint event of the label and do the painting there. Second would be nicer I think.
And is there any reason why you load the file as a QImage to convert it then to a QPixmap?
nunnu
16th September 2010, 16:11
Hi
Thanks for the help. Could you tell me the code snippet to do the same(reimplement the paint event of the label and paint there).
I am new to Qt and I used this snippet from an example "Image Viewer". I load an image file using QImage.
dflo
8th April 2011, 06:03
In reverse order:
QPixmap pixmap(filename);
if (pixmap.isNull())
...
class MySuperCoolLabel (QLabel);
void MySuperCoolLabel::paintEvent (QPaintEvent *event)
{
painter = QPainter(this);
painter.save();
painter.drawPixmap(0, 0, my_pixmap);
painter.setFont(font());
painter.drawText(x, y, my_text);
painter.restore();
}
Please read the class documentation in addition to the tutorials.
yycking
22nd April 2011, 02:32
How about this
label->setStyleSheet("background-image: url(logobackground.png)");
6277
DanH
23rd April 2011, 18:43
Use the image to set the background, then write a normal label.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.