Important: Please read the Qt Code of Conduct -

QMessageBox with QSpinBox

  • Hello,
    is it possible to put in QMessageBox a QSpinBox?

  • Hi! No, that's not possible. But you can make your own "message box" by creating a custom widget that inherits from QDialog.

  • Lifetime Qt Champion

    While it's possible to do using the property based version,
    it often do not work as you
    want and as @Wieland says, the best option is to make your own.

    However, for fun/test code, you can do

    void MainWindow::on_pushButton_released() {
      QMessageBox msgBox;
      QSpinBox* b = new QSpinBox();
      if (msgBox.layout())
      msgBox.setText("The document has been modified.");

    and get

    alt text

    But its not useful in production code as they might change the QMessagebox
    and your code might suddenly stop working so create a new one based on QDialog is the way to go.
    Also as you can see, its comes after OK and might look even stranger if u set more of the flags/options.

Log in to reply