Set Window Icon in QMessageBox
-
Hi,
I would like to set an icon for the window of QMessageBox
Below is the code :QMessageBox::StandardButton popupYesNoBox(QWidget *parent, const QString &message, const QString &title) { QMessageBox qmsg; //qmsg.setWindowIcon(QIcon(":/image.png")); return qmsg.question(parent, title, message, QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No)); }
When I uncomment the second line, it says "cannot convert from 'const char [12]' to 'QIcon'
Source or target has incomplete type"
I am using the same icon, in FileDialogs its working fine.Kindly help.
-
@MTOLANI
You're not getting the right overload of theQIcon()
constructor.In any case (not that I know about this) the examples I see for
.png
convert it toQPixmap
first. This is supposed to work:QPixmap pixmap = QPixmap(":/image.png"); qmsg.setWindowIcon(QIcon(pixmap));
-
Hi,
No QPixelMap doesn't work.
I am calling the above function popupYesNoBox from another class with QWidget *parent as NULL.auto response = nw::popupYesNoBox(NULL, tr("Previous copy exists " "\n\n Select No" "\n\n Select Yes"), tr("Backup file "));
Is there something i could do by setting the parent?
-
@MTOLANI said in Set Window Icon in QMessageBox:
I am using the same icon, in FileDialogs its working fine.
Could you post that code snippet?
For me, it looks like you're forgetting the #include <QIcon> in the file that holds popupYesNoBox() method.