QMessagebox: lack of RejectRole makes close (X) button disabled
-
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:

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.
-
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:

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.
@Dummie1138
Before analyzing further, if I understand your requirement right did you try adding an extra button with RejectRole to keepQMessageBoxhappy and thensetVisible(false)on it? Might (or might not) foolQMessageBoxenough... :) -
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:

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.
@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.