<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QMessagebox: lack of RejectRole makes close (X) button disabled]]></title><description><![CDATA[<p dir="auto">Hi. I have the following code.</p>
<pre><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()-&gt;sendDownloadRequest(2);
}
else if (scopeMsgBox.clickedButton() == allButton){
    Controller::get()-&gt;sendDownloadRequest(0);
}
else{
    return;
}
</code></pre>
<p dir="auto">This is the resulting QMessagebox:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/6614dab8-811d-4467-bd33-25ac4fc1e270.png" alt="a83909aa-c84a-45d0-bdfa-292f45a31877-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">For reasons I am unsure of, this specific QMessagebox causes the close button to become disabled.</p>
<p dir="auto">The workaround so far, based on this <a href="https://stackoverflow.com/questions/7543258/adding-detailed-text-in-qmessagebox-makes-close-x-button-disabled" target="_blank" rel="noopener noreferrer nofollow ugc">post</a>, which suggests QMessageBox does not like it when there are no buttons with the rejectrole:</p>
<pre><code>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()-&gt;sendDownloadRequest(2);
}
else if (scopeMsgBox.clickedButton() == allButton){
    Controller::get()-&gt;sendDownloadRequest(0);
}
else{
    return;
}
</code></pre>
<p dir="auto">But, I do not wish to use this anymore as I don't want the escape button to default to the latestButton.</p>
<p dir="auto">Therefore, <strong>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</strong>.</p>
<p dir="auto">An example elsewhere in the code where the apparent lack of RejectRole <em>does not</em> disable the close button.</p>
<pre><code>    passwordBox = new QDialog(this);
    //Set size of QDialog.
    passwordBox-&gt;resize(450, 160);
    passwordBox-&gt;setMinimumSize(450, 160);
    passwordBox-&gt;setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    passwordBox-&gt;setWindowFlag(Qt::WindowContextHelpButtonHint, false);
    passwordBox-&gt;setWindowTitle("Password input");  //This is a questionable title. Come up w/ something better.
    QVBoxLayout *boxLayout = new QVBoxLayout(passwordBox);
    passwordBox-&gt;setLayout(boxLayout);
    //Add a QLabel
    boxText = new QLabel(this);
    boxLayout-&gt;addWidget(boxText);
    boxText-&gt;setText("Input password:");
    boxText-&gt;setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
    boxText-&gt;setWordWrap(true);
    boxText-&gt;setAlignment(Qt::AlignCenter);
    passwordBox-&gt;setStyleSheet("font: 20px; color: navy; border: none; outline: none;");
    //Add a QLineEdit
    passwordInput = new QLineEdit;
    passwordInput-&gt;setEchoMode(QLineEdit::Password);
    boxLayout-&gt;addWidget(passwordInput);
    //Add a QDialogButtonBox
    QDialogButtonBox *boxButton = new QDialogButtonBox(QDialogButtonBox::Ok, this);
    boxButton-&gt;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-&gt;findChild&lt;QPushButton *&gt;()-&gt;setMinimumSize(80, 50);
    boxLayout-&gt;addWidget(boxButton, 0, Qt::AlignCenter);
    //Read password
    connect(boxButton, SIGNAL(accepted()), this, SLOT(passwordSubmitted()));

    //Connect accepted to a seperate function too
    passwordBox-&gt;open();
</code></pre>
<p dir="auto">Thank you in advance, and please let me know if more info is required.</p>
]]></description><link>https://forum.qt.io/topic/145220/qmessagebox-lack-of-rejectrole-makes-close-x-button-disabled</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Apr 2026 09:06:38 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/145220.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 19 May 2023 11:07:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QMessagebox: lack of RejectRole makes close (X) button disabled on Mon, 22 May 2023 06:50:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dummie1138">@<bdi>Dummie1138</bdi></a> said in <a href="/post/758720">QMessagebox: lack of RejectRole makes close (X) button disabled</a>:</p>
<blockquote>
<p dir="auto">An example elsewhere in the code where the apparent lack of RejectRole does not disable the close button.</p>
</blockquote>
<p dir="auto">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.</p>
]]></description><link>https://forum.qt.io/post/758927</link><guid isPermaLink="true">https://forum.qt.io/post/758927</guid><dc:creator><![CDATA[SimonSchroeder]]></dc:creator><pubDate>Mon, 22 May 2023 06:50:12 GMT</pubDate></item><item><title><![CDATA[Reply to QMessagebox: lack of RejectRole makes close (X) button disabled on Fri, 19 May 2023 11:18:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dummie1138">@<bdi>Dummie1138</bdi></a><br />
Before analyzing further, if I understand your requirement right did you try adding an extra button with <strong>RejectRole</strong> to keep <code>QMessageBox</code> happy and then <code>setVisible(false)</code> on it?  Might (or might not) fool <code>QMessageBox</code> enough... :)</p>
]]></description><link>https://forum.qt.io/post/758721</link><guid isPermaLink="true">https://forum.qt.io/post/758721</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 19 May 2023 11:18:27 GMT</pubDate></item></channel></rss>