Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
5.4.0, 5.12.0
-
None
-
Qt 5.4.0 x64 (MSVC2013)
Windows 8.1 Pro x64
-
-
d8bbb5ee0e60d44a70d29306e607a59caf7fe5bc
Description
When using QMessageBox::addButton(QAbstractButton * button, ButtonRole role), the roles specified are not respected.
The following code creates a message box and sets 3 custom buttons.
When executed, the button that, when clicked, prints "Accepted!" is btn_reject_1. It should be, instead, btn_accept.
If you change the order of the buttons when adding them, you'll see that, no matter what the role assigned, the second button is always the one which ends up getting the AcceptRole (that is, causes the debug to be printed)
QMessageBox mb; mb.setIcon(QMessageBox::Warning); mb.setWindowTitle("Bug"); mb.setText("Is this a bug?"); QPushButton btn_accept("Accept"); QPushButton btn_reject_1("Reject 1"); QPushButton btn_reject_2("Reject 2"); mb.addButton(&btn_accept, QMessageBox::YesRole); mb.addButton(&btn_reject_1, QMessageBox::NoRole); mb.addButton(&btn_reject_2, QMessageBox::RejectRole); connect(&mb, &QMessageBox::accepted, []()->void{qDebug()<<"Accepted!";}); mb.exec();
5.12.0 xcb/Ubuntu 17.10, fusion () Rejected! ret= 0 clickedButton= QPushButton(0x5606f0d37cb0, name="Accept/YesRole") Accepted! ret= 1 clickedButton= QPushButton(0x55a0b50ff6d0, name="Reject 1/NoRole") ret= 2 clickedButton= QPushButton(0x55ac3d5aa520, name="Reject 2/RejectRole")
Attachments
For Gerrit Dashboard: QTBUG-44131 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
247667,9 | Respect roles of buttons added to QMessageBox | 5.12 | qt/qtbase | Status: MERGED | +2 | 0 |
247668,2 | Remove dead code | 5.12 | qt/qtbase | Status: MERGED | +2 | 0 |
247669,6 | tst_QMessageBox: Modernize and simplify code | 5.12 | qt/qtbase | Status: MERGED | +2 | 0 |