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 close button disabled when none of the added buttons are mapped to close
Qt 6.11 is out! See what's new in the release blog

QMessageBox close button disabled when none of the added buttons are mapped to close

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 399 Views 3 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 a QMessageBox with two buttons mapped to ActionRole.

    QMessageBox scopeMsgBox(this);
    scopeMsgBox.setText(tr("<font size = 1>Download latest or all results from the device onto the database?</font>"));
    QAbstractButton *latestButton = scopeMsgBox.addButton(tr("Latest"),
    QMessageBox::ActionRole);
    QAbstractButton *allButton = scopeMsgBox.addButton(tr("All"), QMessageBox::ActionRole);
    scopeMsgBox.setIcon(QMessageBox::Question);
    scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
    scopeMsgBox.setEscapeButton(QMessageBox::Close);
    scopeMsgBox.exec();
    

    In this, the close button on the upper right corner is disabled.
    5a4fd081-cea8-495a-839e-c62e9988ceae-image.png

    According to this post, apparently QMessageBox was reluctant to accept a close when none of the buttons had roles that mapped to close.

    My workaround:

    QMessageBox scopeMsgBox(this);
    scopeMsgBox.setText(tr("<font size = 1>Download latest or all results from the device onto the database?</font>"));
    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.setIcon(QMessageBox::Question);
    scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
    scopeMsgBox.setEscapeButton(QMessageBox::Close);
    scopeMsgBox.exec();
    

    My question is, why is QMessageBox reluctant to accept a close when none of the added buttons had roles that mapped to close? Surely these are only added buttons and shouldn't affect the "inherent buttons" available to QMessageBox. I haven't been able to find anything in the QMessageBox documentation which discusses this, hence this post.

    SGaistS 1 Reply Last reply
    0
    • Dummie1138D Dummie1138

      Hi. I have a QMessageBox with two buttons mapped to ActionRole.

      QMessageBox scopeMsgBox(this);
      scopeMsgBox.setText(tr("<font size = 1>Download latest or all results from the device onto the database?</font>"));
      QAbstractButton *latestButton = scopeMsgBox.addButton(tr("Latest"),
      QMessageBox::ActionRole);
      QAbstractButton *allButton = scopeMsgBox.addButton(tr("All"), QMessageBox::ActionRole);
      scopeMsgBox.setIcon(QMessageBox::Question);
      scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
      scopeMsgBox.setEscapeButton(QMessageBox::Close);
      scopeMsgBox.exec();
      

      In this, the close button on the upper right corner is disabled.
      5a4fd081-cea8-495a-839e-c62e9988ceae-image.png

      According to this post, apparently QMessageBox was reluctant to accept a close when none of the buttons had roles that mapped to close.

      My workaround:

      QMessageBox scopeMsgBox(this);
      scopeMsgBox.setText(tr("<font size = 1>Download latest or all results from the device onto the database?</font>"));
      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.setIcon(QMessageBox::Question);
      scopeMsgBox.setDefaultButton(scopeMsgBox.QMessageBox::standardButton(latestButton));
      scopeMsgBox.setEscapeButton(QMessageBox::Close);
      scopeMsgBox.exec();
      

      My question is, why is QMessageBox reluctant to accept a close when none of the added buttons had roles that mapped to close? Surely these are only added buttons and shouldn't affect the "inherent buttons" available to QMessageBox. I haven't been able to find anything in the QMessageBox documentation which discusses this, hence this post.

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which version of Qt are you using ?
      On which platform ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Dummie1138D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of Qt are you using ?
        On which platform ?

        Dummie1138D Offline
        Dummie1138D Offline
        Dummie1138
        wrote on last edited by
        #3

        @SGaist I am using Qt 5.15.2 (MinGW 32-bit if it helps), on Windows 10.

        SGaistS 1 Reply Last reply
        0
        • Dummie1138D Dummie1138

          @SGaist I am using Qt 5.15.2 (MinGW 32-bit if it helps), on Windows 10.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I might be wrong but I think that your use of ActionRole is wrong in this context. Both actions should be AcceptAction as they do not denote a change but a choice.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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