Displaying an image in a QmessageBox
How to display an image in a message box. I tried
about.setIcon(":/pics/goku3.jpg");
but this is giving me errors. I know I can use the inline checkbox. Here is the complete code to display this field.
void MainWindow::on_actionUmer_s_Program_triggered()
{
QMessageBox about;
about.setText("Umer Program");
about.setInformativeText("Copyright ; 2012 Umer Software Inc.\nI wrote this program for fun.\n);
about.setStandardButtons(QMessageBox::Ok);
about.setIcon(":/pics/goku3.jpg"); // here is the error
about.setDefaultButton(QMessageBox::Ok);
about.show();
about.exec();
}
Also tell me how you can set the size of this image.
source to share
You shouldn't use about.setIcon(":/pics/goku3.jpg");
because the method QMessageBox::setIcon(Icon)
only works with predefined icons
QMessageBox::NoIcon QMessageBox::Question QMessageBox::Information QMessageBox::Warning QMessageBox::Critical
To upload your own photo, you must use:
void setIconPixmap ( const QPixmap & pixmap )
For example:
about.setIconPixmap(QPixMap(":/pics/goku3.jpg"));
Also, if you want to use this format ":/pics/goku3.jpg"
, make sure your file .qrc
(this is a resource file) is configured correctly.
You can get more information from here .
source to share