Results 1 to 5 of 5

Thread: QMessageBox - Text in the buttons

  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QMessageBox - Text in the buttons

    Hi,

    I had this:
    Qt Code:
    1. int r = QMessageBox::question(this, tr("Delete CD"), tr("delete \"%1\" and all its tracks?")
    2. .arg(record.value(cd_idartista).toString()),
    3. QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape);
    4.  
    5. if(r == QMessageBox::No)
    6. ...
    To copy to clipboard, switch view to plain text mode 

    The problem is that i get a "Yes" and "No" text in the Buttons, when i wanted "Sim" and "Não".
    Then i tried this:
    Qt Code:
    1. int result = QMessageBox::question(this,
    2. trUtf8("Delete CD"),
    3. trUtf8("Eliminar \"%1\" e todas as pistas?").arg(record.value(cd_titulo).toString()),
    4. trUtf8("&Sim"),
    5. trUtf8("&Não"),
    6. QString::null,
    7. 1,
    8. 1 );
    To copy to clipboard, switch view to plain text mode 
    ... but it looks as this is considered to be obsolete(http://doc.trolltech.com/4.6/qmessagebox-obsolete.html).

    Now i have:
    Qt Code:
    1. QMessageBox msgBox;
    2. msgBox.setText(trUtf8("Delete CD"));
    3. msgBox.setInformativeText(record.value(cd_titulo).toString());
    4. msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    5. msgBox.setDefaultButton(QMessageBox::No);
    6.  
    7. if(msgBox.exec() == QMessageBox::No)
    8. ...
    To copy to clipboard, switch view to plain text mode 

    Now ... how do i change the Yes/No text by Sim/Não ?

    Thanks

  2. #2
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMessageBox - Text in the buttons

    It was easy after all ...
    Qt Code:
    1. QMessageBox msgBox;
    2. msgBox.setText(trUtf8("Eliminar CD"));
    3. msgBox.setInformativeText(record.value(cd_titulo).toString());
    4. QAbstractButton *myYesButton = msgBox.addButton(trUtf8("Sim"), QMessageBox::YesRole);
    5. QAbstractButton *myNoButton = msgBox.addButton(trUtf8("Não"), QMessageBox::NoRole);
    6. msgBox.setIcon(QMessageBox::Question);
    7. msgBox.exec();
    8.  
    9. if(msgBox.clickedButton() == myNoButton)
    10. {
    11. db.rollback();
    12. return;
    13. }
    14. ...
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMessageBox - Text in the buttons

    There's also one good way:
    Qt Code:
    1. QMessageBox msgBox(
    2. QMessageBox::Question,
    3. trUtf8("Eliminar CD"),
    4. record.value(cd_titulo).toString(),
    5. QMessageBox::Yes | QMessageBox::No);
    6.  
    7. msgBox.setButtonText(QMessageBox::Yes, trUtf8("Sim"));
    8. msgBox.setButtonText(QMessageBox::No, trUtf8("Não"));
    9.  
    10. if (msgBox.exec() == QMessageBox::No) {
    11. db.rollback();
    12. return;
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by kefir500; 20th August 2013 at 12:27.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMessageBox - Text in the buttons

    Qt Code:
    1. QTranslator qtTrans;
    2. qtTrans.load("qt_pt.qm");
    3. app.installTranslator(&qtTrans);
    4.  
    5. // ...
    6.  
    7. int r = QMessageBox::question(this, tr("Delete CD"), tr("delete \"%1\" and all its tracks?")
    8. .arg(record.value(cd_idartista).toString()),
    9. QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    Cupidvogel (21st June 2015)

  6. #5
    Join Date
    May 2014
    Posts
    136
    Thanks
    72
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    MacOS X Windows

    Default Re: QMessageBox - Text in the buttons

    Any idea on how to access the 'Show Details..." button of a QMessageBox and add custom text in place of the "Show Details..." and "Hide Details..." texts?

Similar Threads

  1. SETTING THE TEXT COLOR FOR QMessageBox
    By vinkakarun in forum Newbie
    Replies: 2
    Last Post: 5th November 2009, 17:32
  2. QMessageBox ignores nobr with rich text format
    By daggilli in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2008, 04:54
  3. QMessageBox buttons appearance
    By yartov in forum Qt Programming
    Replies: 6
    Last Post: 26th June 2008, 02:36
  4. Replies: 3
    Last Post: 25th April 2007, 13:43
  5. widget for text AND buttons
    By nongentesimus in forum Newbie
    Replies: 2
    Last Post: 16th June 2006, 14:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.