View Full Version : How to inset a png image in a dialog
graciano
17th January 2009, 17:36
Hi
I want to use a smilie to show if the data entered in a lineEdit e valid.
:) for true or :( for false.
I have two images: true.png and false.png.
How can i do this in Qt and what classes can i use?
Thanks
THRESHE
17th January 2009, 18:39
You can use QLabel with setPixmap function and connect lineEdit's textChanged signal to the slot that changes image
For instance
connect(lineEddit, SIGNAL(textChanged(const QString& text)), this, SLOT(changePixmap(const QString& text)))
yourDialog::changePixmap(const QString& text)
{
if(text == "Valid")
pixmapLable->setPixmap(QPixmap(true.png));
else
pixmapLable->setPixmap(QPixmap(false.png));
}
graciano
17th January 2009, 19:51
Thanks
I was blind about the label! In my mind i was only thinking of text:rolleyes:
By the way... i created a folder "pixmaps" where i stores the smilies.
The i used something like:
...
png = new QLabel();
png->setPixmap(QPixmap("pixmaps/happy.png"));
...
Is this a good practice or are there other ways to store large collections of images?
And thanks again for the preciouse help.
GioFX
17th January 2009, 20:01
you should use qrc
http://doc.trolltech.com/4.4/resources.html
graciano
17th January 2009, 20:08
Thanks ... i will take a look at the link.
rexi
17th January 2009, 22:29
You could also consider using the QLineEdit::textEdited() signal instead of QLineEdit::textChanged(). The first is emitted only when the user changes the contents, while the latter is also emitted when the application itself changes the contents. Not a great deal in most cases, but I found it helpful to know the difference ;)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.