QMessageBox without Icon

  • 9 months ago
Comment

ChatGPT
1 / 1

In Qt, the QMessageBox class provides a way to display various types of message boxes, including icons. If you want to create a QMessageBox without an icon, you can customize the message box by specifying a QMessageBox::NoIcon value as the icon type. Here's how you can do it:

cpp
#include <QMessageBox>

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

QMessageBox msgBox;
msgBox.setIcon(QMessageBox::NoIcon); // Set no icon
msgBox.setText("This is a message without an icon.");
msgBox.exec();

return app.exec();
}

In this example, the setIcon function is called with the QMessageBox::NoIcon value to indicate that no icon should be displayed. The setText function is used to set the message text, and then the exec function displays the message box.

Keep in mind that not displaying an icon might make the message box less visually distinguishable from other windows. It's a good practice to use a proper icon that matches the message's importance or type.