1

enter image description here

I am trying to adjust a QMessageBox, but somehow I did not find anything about how to address the WindowLogo and Name of the occurring Message Box correctly. It would be additionally nice to center the Button "ok" horizontally. My Code (Qt/C++) and the approach to address the MessageBox Window Icon and Name so far:

// just for the color understanding
const QColor BG_COLOR = QColor(125,125,125);
QString setColorBG = "{background: rgb("
           + QString::number(BG_COLOR.red())   + ","
           + QString::number(BG_COLOR.green()) + ","
           + QString::number(BG_COLOR.blue())  + ");}";

QMessageBox msg;
msg.setText("Please select images.");
msg.setIcon(QMessageBox::Warning);
msg.setWindowIcon(QIcon()); // has no effect
msg.setWindowIconText("Warning"); // has no effect
msg.setStyleSheet("QMessageBox QPushButton{background: rgb(173,173,173);}"
                  "QMessageBox " + setColorBG);
msg.exec();

Can the text, currently reading "PanoramaCreator", and the logo next to it be addressed by a similar approach or is something completely different necessary?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Miau
  • 301
  • 1
  • 3
  • 12
  • 1
    Concerning the window icon... From Qt doc.: [Widget::windowIcon](https://doc.qt.io/qt-5/qwidget.html#windowIcon-prop): _If no icon has been set, windowIcon() returns the application icon_ I would consider the [QIcon()](https://doc.qt.io/qt-5/qicon.html#QIcon) aka null icon as no icon. You could try to make a pixmap with one transparent pixel and use this as icon. – Scheff's Cat Jul 28 '21 at 03:36
  • 1
    Concerning the title... [Widget::windowTitle](https://doc.qt.io/qt-5/qwidget.html#windowTitle-prop). Btw. Why didn't you use [the other constructor of QMessageBox](https://doc.qt.io/qt-5/qmessagebox.html#QMessageBox-1) where you can pass nearly everything as argument? – Scheff's Cat Jul 28 '21 at 03:39
  • 1
    _It would be additionally nice to center the Button "ok" horizontally._ I assume the Qt message box wraps / follows some platform style. Thus, I have doubts whether the alignment of the button can be changed. If you intend to achieve this at all, I would drop the `QMessageBox` and "manually" re-build it by [QDialog](https://doc.qt.io/qt-5/qdialog.html), a `QGridLayout`, and `QLabel`s. There is a `QDialogButtonBox` which offers [QDialogButtonBox::centerButtons](https://doc.qt.io/qt-5/qdialogbuttonbox.html#centerButtons-prop). (I must admit I saw it the first time today and never used it.) – Scheff's Cat Jul 28 '21 at 03:46
  • 1
    Thanks, you are right, the layout of QMessageBox seems to be fixed. I got confused by the various similar reading options that are given. To set the title and icon the correct way, for example according to the MainWindow, msg.setWindowIcon(this->windowIcon()); and msg.setWindowTitle(this->windowTitle()); can be used. When no Icon is set, the broken Icon appears, so a transparent logo would be a soultion to set "no logo". – Miau Jul 28 '21 at 07:15

0 Answers0