Custom QMessageBox Buttons: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Cleanup)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:snippets]]<br />[[Category:HowTo]]
{{LangSwitch}}
 
[[Category:snippets]]
[toc align_right=&quot;yes&amp;quot; depth=&quot;2&amp;quot;]
[[Category:HowTo]]
 
'''English''' [[Custom_QMessageBox_Buttons_Bulgarian|Български]]
 
= Custom QMessageBox Buttons =
 
== Introduction ==
== Introduction ==


The following code snippet demonstrate how to customize &quot;QMessageBox&amp;quot;:http://doc.qt.io/qt-4.8/QMessageBox.html by adding custom text and buttons using method &quot;addButton&amp;quot;:http://doc.qt.io/qt-4.8/qmessagebox.html#addButton.
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 ==


<code><br />QMessageBox msgBox;<br />msgBox.setText(tr(&quot;Confirm?&quot;));<br />QAbstractButton* pButtonYes = msgBox.addButton(tr(&quot;Yeah!&quot;), QMessageBox::YesRole);<br />msgBox.addButton(tr(&quot;Nope&amp;quot;), QMessageBox::NoRole);
<code>
QMessageBox msgBox;
msgBox.setText(tr("Confirm?"));
QAbstractButton* pButtonYes = msgBox.addButton(tr("Yeah!"), QMessageBox::YesRole);
msgBox.addButton(tr("Nope"), QMessageBox::NoRole);


msgBox.exec&amp;amp;#40;&amp;#41;;
msgBox.exec();


if(msgBox.clickedButton() == pButtonYes)<br />{<br /> //Execute command<br />}
if (msgBox.clickedButton()==pButtonYes) {
    //Execute command
}
</code>

Latest revision as of 13:21, 28 June 2015

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

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
}