the icon.jpg how loaded in Qt Creator ? I have to create image folder?
-
code like this for alert boxes with image
QPixmap myIcon(":/images/icon.jpg"); //
the icon.jpg how loaded in Qt Creator ? I have to create image folder?QMessageBox msgBox2; msgBox2.setWindowTitle("Serious Question"); msgBox2.setText("Am I an awesome guy?"); msgBox2.addButton("Seriously Yes!", QMessageBox::YesRole); msgBox2.addButton("Seriously No!", QMessageBox::NoRole); QPixmap myIcon(":/images/icon.jpg"); msgBox2.setIconPixmap(myIcon); msgBox2.setIcon(QMessageBox::Question); msgBox2.exec();
-
@lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:
the icon.jpg how loaded in Qt Creator ? I have to create image folder?
Can you explain it in different words? I have no idea what you mean.
I'll give a general answer, it may not apply to your case:
The
:/
notation us used for Qt Resources, you can read all about them here.Normally, if you have a filesystem structure like:
SomeDirectory | *- yourResourceFile.qrc | *- images | * icon.jpg
and you just add your icon to QRC via Qt Creator's editor - then your path to that file will indeed become
:/images/icon.jpg
. But the power of QRC system is that you can create any directory structure you like, add prefixes, aliases etc. So a really accurate answer toI have to create image folder?
isdepends
;-) -
@lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:
QPixmap myIcon(":/images/icon.jpg");
this ebook chapter about message dialog windows/alerts
says this QPixmap myIcon(":/images/icon.jpg");
but Not say how put image or create resource file ... so you mean use this https://doc.qt.io/qt-5/resources.html ... ? -
Yes, use the docs. It's really easy, don't worry. For your use case you just need to add a resource file and one entry inside it. You can do it manually (like in the documentation) or using Qt Creator to help you.
-
@lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:
this ebook
Which ebook do you mean? My guess is that the resource system is explained somewhere else in that book.
-
@lse123 said in the icon.jpg how loaded in Qt Creator ? I have to create image folder?:
QPixmap myIcon(":/images/icon.jpg");
msgBox2.setIconPixmap(myIcon);
msgBox2.setIcon(QMessageBox::Question);
msgBox2.exec();The problem was and solve it is must comment the line in BOLD below because overwrites the seticonPixmap with "?" question icon...
msgBox2.setIconPixmap(myIcon);
> msgBox2.setIcon(QMessageBox::Question);