Custom QMessageBox Buttons: Difference between revisions
Jump to navigation
Jump to search
AutoSpider (talk | contribs) (Remove non-functioning "toc" command) |
(Cleanup) |
||
Line 1: | Line 1: | ||
{{ | {{LangSwitch}} | ||
[[Category:snippets]] | [[Category:snippets]] | ||
[[Category:HowTo]] | [[Category:HowTo]] | ||
== Introduction == | == Introduction == | ||
The following code snippet demonstrate how to customize | The following code snippet demonstrate how to customize {{DocLink|QMessageBox}} by adding custom text and buttons using method [http://doc.qt.io/qt-5/qmessagebox.html#addButton addButton]. | ||
== Code Snippet == | == Code Snippet == | ||
Line 23: | Line 16: | ||
msgBox.exec(); | msgBox.exec(); | ||
if(msgBox.clickedButton() == pButtonYes) | if (msgBox.clickedButton()==pButtonYes) { | ||
{ | //Execute command | ||
} | } | ||
</code> |
Latest revision as of 13:21, 28 June 2015
Introduction
The following code snippet demonstrate how to customize QMessageBox by adding custom text and buttons using method addButton.
Code Snippet
QMessageBox msgBox;
msgBox.setText(tr("Confirm?"));
QAbstractButton* pButtonYes = msgBox.addButton(tr("Yeah!"), QMessageBox::YesRole);
msgBox.addButton(tr("Nope"), QMessageBox::NoRole);
msgBox.exec();
if (msgBox.clickedButton()==pButtonYes) {
//Execute command
}