QMessageBox with QSpinBox



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


  • Moderators

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


  • Qt Champions 2016

    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.layout()->addWidget(b);
      msgBox.setText("The document has been modified.");
      msgBox.exec();
    }
    
    

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.