Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying Image in QmessageBox

Tags:

c++

qt

messagebox

How can I display an image in a message box. I tried

about.setIcon(":/pics/goku3.jpg");

but it gives me errors. I know I can use the built-in about box. Here is the full code for displaying this about box.

void MainWindow::on_actionUmer_s_Program_triggered()
{
    QMessageBox about;

    about.setText("Umer's 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();
}

Please also tell me how can set the size of that image.

like image 312
Umer Farooq Avatar asked Mar 07 '12 12:03

Umer Farooq


1 Answers

You should not use about.setIcon(":/pics/goku3.jpg"); because the QMessageBox::setIcon(Icon) method only works with predefined icons that are

QMessageBox::NoIcon
QMessageBox::Question
QMessageBox::Information
QMessageBox::Warning
QMessageBox::Critical

To load your own picture your should 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 have your .qrc file (this is a resource file) configured correctly.

More information you can get from here.

like image 93
Stely Avatar answered Sep 30 '22 18:09

Stely