Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMessagebox: lack of RejectRole makes close (X) button disabled

QMessagebox: lack of RejectRole makes close (X) button disabled

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 343 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    Hi. I have the following code.

    QMessageBox scopeMsgBox(this);
    
    QAbstractButton *latestButton = scopeMsgBox.addButton(tr("Latest"), QMessageBox::ActionRole);
    QAbstractButton *allButton = scopeMsgBox.addButton(tr("All"), QMessageBox::ActionRole);
    scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
    scopeMsgBox.exec();
    
    if(scopeMsgBox.clickedButton() == latestButton){
        Controller::get()->sendDownloadRequest(2);
    }
    else if (scopeMsgBox.clickedButton() == allButton){
        Controller::get()->sendDownloadRequest(0);
    }
    else{
        return;
    }
    

    This is the resulting QMessagebox:
    a83909aa-c84a-45d0-bdfa-292f45a31877-image.png

    For reasons I am unsure of, this specific QMessagebox causes the close button to become disabled.

    The workaround so far, based on this post, which suggests QMessageBox does not like it when there are no buttons with the rejectrole:

    QMessageBox scopeMsgBox(this);
    
    QAbstractButton *latestButton = scopeMsgBox.addButton(tr("Latest"), QMessageBox::RejectRole); //This is not a RejectRole but QMessageBox was reluctant to accept a close when none of the buttons had roles that mapped to close.
    QAbstractButton *allButton = scopeMsgBox.addButton(tr("All"), QMessageBox::ActionRole);
    scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
    scopeMsgBox.exec();
    
    if(scopeMsgBox.clickedButton() == latestButton){
        Controller::get()->sendDownloadRequest(2);
    }
    else if (scopeMsgBox.clickedButton() == allButton){
        Controller::get()->sendDownloadRequest(0);
    }
    else{
        return;
    }
    

    But, I do not wish to use this anymore as I don't want the escape button to default to the latestButton.

    Therefore, I would like to have the closeButton not be disabled despite a lack of reject roles. I do not want to add more visible buttons to the QMessagebox.

    An example elsewhere in the code where the apparent lack of RejectRole does not disable the close button.

        passwordBox = new QDialog(this);
        //Set size of QDialog.
        passwordBox->resize(450, 160);
        passwordBox->setMinimumSize(450, 160);
        passwordBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        passwordBox->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
        passwordBox->setWindowTitle("Password input");  //This is a questionable title. Come up w/ something better.
        QVBoxLayout *boxLayout = new QVBoxLayout(passwordBox);
        passwordBox->setLayout(boxLayout);
        //Add a QLabel
        boxText = new QLabel(this);
        boxLayout->addWidget(boxText);
        boxText->setText("Input password:");
        boxText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
        boxText->setWordWrap(true);
        boxText->setAlignment(Qt::AlignCenter);
        passwordBox->setStyleSheet("font: 20px; color: navy; border: none; outline: none;");
        //Add a QLineEdit
        passwordInput = new QLineEdit;
        passwordInput->setEchoMode(QLineEdit::Password);
        boxLayout->addWidget(passwordInput);
        //Add a QDialogButtonBox
        QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this);
        boxButton->setStyleSheet("QPushButton {border: 2px solid #8f8f91;border-radius: 9px;background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #f6f7fa, stop: 1 #dadbde);font: 25px;outline: none;}"
        "QPushButton:pressed {background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa) }");
        boxButton->findChild<QPushButton *>()->setMinimumSize(80, 50);
        boxLayout->addWidget(boxButton, 0, Qt::AlignCenter);
        //Read password
        connect(boxButton, SIGNAL(accepted()), this, SLOT(passwordSubmitted()));
    
        //Connect accepted to a seperate function too
        passwordBox->open();
    

    Thank you in advance, and please let me know if more info is required.

    JonBJ S 2 Replies Last reply
    0
    • Dummie1138D Dummie1138

      Hi. I have the following code.

      QMessageBox scopeMsgBox(this);
      
      QAbstractButton *latestButton = scopeMsgBox.addButton(tr("Latest"), QMessageBox::ActionRole);
      QAbstractButton *allButton = scopeMsgBox.addButton(tr("All"), QMessageBox::ActionRole);
      scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
      scopeMsgBox.exec();
      
      if(scopeMsgBox.clickedButton() == latestButton){
          Controller::get()->sendDownloadRequest(2);
      }
      else if (scopeMsgBox.clickedButton() == allButton){
          Controller::get()->sendDownloadRequest(0);
      }
      else{
          return;
      }
      

      This is the resulting QMessagebox:
      a83909aa-c84a-45d0-bdfa-292f45a31877-image.png

      For reasons I am unsure of, this specific QMessagebox causes the close button to become disabled.

      The workaround so far, based on this post, which suggests QMessageBox does not like it when there are no buttons with the rejectrole:

      QMessageBox scopeMsgBox(this);
      
      QAbstractButton *latestButton = scopeMsgBox.addButton(tr("Latest"), QMessageBox::RejectRole); //This is not a RejectRole but QMessageBox was reluctant to accept a close when none of the buttons had roles that mapped to close.
      QAbstractButton *allButton = scopeMsgBox.addButton(tr("All"), QMessageBox::ActionRole);
      scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
      scopeMsgBox.exec();
      
      if(scopeMsgBox.clickedButton() == latestButton){
          Controller::get()->sendDownloadRequest(2);
      }
      else if (scopeMsgBox.clickedButton() == allButton){
          Controller::get()->sendDownloadRequest(0);
      }
      else{
          return;
      }
      

      But, I do not wish to use this anymore as I don't want the escape button to default to the latestButton.

      Therefore, I would like to have the closeButton not be disabled despite a lack of reject roles. I do not want to add more visible buttons to the QMessagebox.

      An example elsewhere in the code where the apparent lack of RejectRole does not disable the close button.

          passwordBox = new QDialog(this);
          //Set size of QDialog.
          passwordBox->resize(450, 160);
          passwordBox->setMinimumSize(450, 160);
          passwordBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
          passwordBox->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
          passwordBox->setWindowTitle("Password input");  //This is a questionable title. Come up w/ something better.
          QVBoxLayout *boxLayout = new QVBoxLayout(passwordBox);
          passwordBox->setLayout(boxLayout);
          //Add a QLabel
          boxText = new QLabel(this);
          boxLayout->addWidget(boxText);
          boxText->setText("Input password:");
          boxText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
          boxText->setWordWrap(true);
          boxText->setAlignment(Qt::AlignCenter);
          passwordBox->setStyleSheet("font: 20px; color: navy; border: none; outline: none;");
          //Add a QLineEdit
          passwordInput = new QLineEdit;
          passwordInput->setEchoMode(QLineEdit::Password);
          boxLayout->addWidget(passwordInput);
          //Add a QDialogButtonBox
          QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this);
          boxButton->setStyleSheet("QPushButton {border: 2px solid #8f8f91;border-radius: 9px;background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #f6f7fa, stop: 1 #dadbde);font: 25px;outline: none;}"
          "QPushButton:pressed {background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa) }");
          boxButton->findChild<QPushButton *>()->setMinimumSize(80, 50);
          boxLayout->addWidget(boxButton, 0, Qt::AlignCenter);
          //Read password
          connect(boxButton, SIGNAL(accepted()), this, SLOT(passwordSubmitted()));
      
          //Connect accepted to a seperate function too
          passwordBox->open();
      

      Thank you in advance, and please let me know if more info is required.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Dummie1138
      Before analyzing further, if I understand your requirement right did you try adding an extra button with RejectRole to keep QMessageBox happy and then setVisible(false) on it? Might (or might not) fool QMessageBox enough... :)

      1 Reply Last reply
      0
      • Dummie1138D Dummie1138

        Hi. I have the following code.

        QMessageBox scopeMsgBox(this);
        
        QAbstractButton *latestButton = scopeMsgBox.addButton(tr("Latest"), QMessageBox::ActionRole);
        QAbstractButton *allButton = scopeMsgBox.addButton(tr("All"), QMessageBox::ActionRole);
        scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
        scopeMsgBox.exec();
        
        if(scopeMsgBox.clickedButton() == latestButton){
            Controller::get()->sendDownloadRequest(2);
        }
        else if (scopeMsgBox.clickedButton() == allButton){
            Controller::get()->sendDownloadRequest(0);
        }
        else{
            return;
        }
        

        This is the resulting QMessagebox:
        a83909aa-c84a-45d0-bdfa-292f45a31877-image.png

        For reasons I am unsure of, this specific QMessagebox causes the close button to become disabled.

        The workaround so far, based on this post, which suggests QMessageBox does not like it when there are no buttons with the rejectrole:

        QMessageBox scopeMsgBox(this);
        
        QAbstractButton *latestButton = scopeMsgBox.addButton(tr("Latest"), QMessageBox::RejectRole); //This is not a RejectRole but QMessageBox was reluctant to accept a close when none of the buttons had roles that mapped to close.
        QAbstractButton *allButton = scopeMsgBox.addButton(tr("All"), QMessageBox::ActionRole);
        scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
        scopeMsgBox.exec();
        
        if(scopeMsgBox.clickedButton() == latestButton){
            Controller::get()->sendDownloadRequest(2);
        }
        else if (scopeMsgBox.clickedButton() == allButton){
            Controller::get()->sendDownloadRequest(0);
        }
        else{
            return;
        }
        

        But, I do not wish to use this anymore as I don't want the escape button to default to the latestButton.

        Therefore, I would like to have the closeButton not be disabled despite a lack of reject roles. I do not want to add more visible buttons to the QMessagebox.

        An example elsewhere in the code where the apparent lack of RejectRole does not disable the close button.

            passwordBox = new QDialog(this);
            //Set size of QDialog.
            passwordBox->resize(450, 160);
            passwordBox->setMinimumSize(450, 160);
            passwordBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
            passwordBox->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
            passwordBox->setWindowTitle("Password input");  //This is a questionable title. Come up w/ something better.
            QVBoxLayout *boxLayout = new QVBoxLayout(passwordBox);
            passwordBox->setLayout(boxLayout);
            //Add a QLabel
            boxText = new QLabel(this);
            boxLayout->addWidget(boxText);
            boxText->setText("Input password:");
            boxText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
            boxText->setWordWrap(true);
            boxText->setAlignment(Qt::AlignCenter);
            passwordBox->setStyleSheet("font: 20px; color: navy; border: none; outline: none;");
            //Add a QLineEdit
            passwordInput = new QLineEdit;
            passwordInput->setEchoMode(QLineEdit::Password);
            boxLayout->addWidget(passwordInput);
            //Add a QDialogButtonBox
            QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this);
            boxButton->setStyleSheet("QPushButton {border: 2px solid #8f8f91;border-radius: 9px;background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #f6f7fa, stop: 1 #dadbde);font: 25px;outline: none;}"
            "QPushButton:pressed {background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, stop: 1 #f6f7fa) }");
            boxButton->findChild<QPushButton *>()->setMinimumSize(80, 50);
            boxLayout->addWidget(boxButton, 0, Qt::AlignCenter);
            //Read password
            connect(boxButton, SIGNAL(accepted()), this, SLOT(passwordSubmitted()));
        
            //Connect accepted to a seperate function too
            passwordBox->open();
        

        Thank you in advance, and please let me know if more info is required.

        S Offline
        S Offline
        SimonSchroeder
        wrote on last edited by
        #3

        @Dummie1138 said in QMessagebox: lack of RejectRole makes close (X) button disabled:

        An example elsewhere in the code where the apparent lack of RejectRole does not disable the close button.

        Well, there is a difference between QDialog and QMessageBox. Choose the right one for your task instead of trying to trick the wrong one into doing things it is not meant to do.

        1 Reply Last reply
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved