Missing function entry in QMessageBox documentation
I was wondering about the fact that I can't find a function called "setButtonText(QStandardButton, const QString &)" in Qt's documentation of QMessageBox.
In fact, this function exists and works great, so maybe there is some update missing in the documentation?!
"setButtonText":http://qt-project.org/doc/qt-5/qmessagebox-obsolete.html#setButtonText is obsolete in Qt 5 and so probably missing.
Oh, well that could be the solution. But I'm wondering why this functionallity is obsolete in Qt 5, because I don't know an easier way to change the text of a QStandardButton, do you?
[quote author="Binary91" date="1415541360"]Oh, well that could be the solution. But I'm wondering why this functionallity is obsolete in Qt 5, because I don't know an easier way to change the text of a QStandardButton, do you?[/quote]I think the idea is this: It's better to set the correct text at initialization, rather than setting one text first and then changing it later.
The button text can be set through the QMessageBox constructor, or through addButton(). So, setButtonText() is not needed anymore.
Can you think of a use-case where these functions are not suitable?
[quote]The button text can be set through the QMessageBox constructor[/quote]Hm... maybe I'm not able to see it, but which constructor of QMessageBox accepts QStrings related to the text of its StandardButtons?
I see only two constructors there:
QMessageBox(Icon, const QString &, const QString &, StandardButtons, QWidget *, Qt::WindowFlags)"
Maybe I don't get it...
Sorry, my mistake -- there's no constructor that lets you specify custom text.
b2.addButton("My OK", QMessageBox::AcceptRole);
b2.addButton("My Cancel", QMessageBox::RejectRole);
By the way, you cannot change the text of a standard button. setButtonText() only works on custom buttons.
Yeah, this would be the second way I think, but then, on my mind, the setButtonText() method is not that obsolete..
[quote]By the way, you cannot change the text of a standard button. setButtonText() only works on custom buttons.[/quote]That's weird, because it works fine for me:
@QMessageBox *msgbox = new QMessageBox(QMessageBox::Question, "my message", "Does it work?", QMessageBox::Yes | QMessageBox::No);
msgbox->setButtonText(QMessageBox::No, "Oh noooo");@
Did you try that on your system and it failed? That would be interesting I think...
Ah, I see. I misunderstood how to use that function.
The function takes an integer as the first argument...
void setButtonText(int button, const QString & text)
...so I gave it a button index...
QMessageBox msgbox(QMessageBox::NoIcon, "My Message", "Click Something!", QMessageBox::Ok | QMessageBox::Cancel);
msgbox.setButtonText(0, "Click Me!");
msgbox.setButtonText(1, "Go Away!");
...which didn't work.
Anyway, I think I know why the Qt devs deprecated these functions. The old API is ambiguous and inconsistent. See http://qt-project.org/doc/qt-5/qmessagebox-obsolete.html
- The first version of QMessageBox::information() takes int arguments, where we're supposed to provide a QMessageBox::StandardButton value
- The second version of QMessageBox::information() also takes int arguments, but we're supposed to provide button index numbers.
By just looking at the function signature, it is not obvious whether I should provide a button index value or a StandardButton value.
To remove this ambiguity, all the QMessageBox functions which take int arguments (including setButtonText()) are now deprecated.