Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change QMessageBox Icon and Title

I am creating a ui app with Qt c++.

I have a error message that I have created by using QMessageBox Class like :

QMessageBox errorMessage;
errorMessage.critical(0, "Error", "An error has occured !");
errorMessage.setFixedSize(500, 200);

It is like:

enter image description here

And I want to change the red circled things which are the icon and the title.

enter image description here

I would appreciate any help.

Thanks in advance.

like image 564
BUY Avatar asked Jul 02 '18 06:07

BUY


1 Answers

However you can use of QMessageBox::critical(0, "Error", "An error has occured !"); because critical(...) method is static and theres no need for create an instance of QMessageBox.

Use bellow code :

QMessageBox mb("Application Name",
                           "Hardware failure.\n\nDisk error detected\nDo you want to stop?",
                           QMessageBox::NoIcon,
                           QMessageBox::Yes | QMessageBox::Default,
                           QMessageBox::NoButton,
                           QMessageBox::NoButton);

QPixmap exportSuccess("/media/msi/Information/Pictures/Icons/Icons Pack/PNG/48X48/about.png");
mb.setIconPixmap(exportSuccess);
mb.exec();

enter image description here

This example work 100%

like image 183