PDA

View Full Version : QMessageBox - Text in the buttons



graciano
7th March 2010, 18:44
Hi,

I had this:


int r = QMessageBox::question(this, tr("Delete CD"), tr("delete \"%1\" and all its tracks?")
.arg(record.value(cd_idartista).toString()),
QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape);

if(r == QMessageBox::No)
...


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:


int result = QMessageBox::question(this,
trUtf8("Delete CD"),
trUtf8("Eliminar \"%1\" e todas as pistas?").arg(record.value(cd_titulo).toString()),
trUtf8("&Sim"),
trUtf8("&Não"),
QString::null,
1,
1 );

... but it looks as this is considered to be obsolete(http://doc.trolltech.com/4.6/qmessagebox-obsolete.html).

Now i have:


QMessageBox msgBox;
msgBox.setText(trUtf8("Delete CD"));
msgBox.setInformativeText(record.value(cd_titulo). toString());
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);

if(msgBox.exec() == QMessageBox::No)
...


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

Thanks

graciano
8th March 2010, 00:32
It was easy after all ...


QMessageBox msgBox;
msgBox.setText(trUtf8("Eliminar CD"));
msgBox.setInformativeText(record.value(cd_titulo). toString());
QAbstractButton *myYesButton = msgBox.addButton(trUtf8("Sim"), QMessageBox::YesRole);
QAbstractButton *myNoButton = msgBox.addButton(trUtf8("Não"), QMessageBox::NoRole);
msgBox.setIcon(QMessageBox::Question);
msgBox.exec();

if(msgBox.clickedButton() == myNoButton)
{
db.rollback();
return;
}
...

kefir500
20th August 2013, 11:06
There's also one good way:


QMessageBox msgBox(
QMessageBox::Question,
trUtf8("Eliminar CD"),
record.value(cd_titulo).toString(),
QMessageBox::Yes | QMessageBox::No);

msgBox.setButtonText(QMessageBox::Yes, trUtf8("Sim"));
msgBox.setButtonText(QMessageBox::No, trUtf8("Não"));

if (msgBox.exec() == QMessageBox::No) {
db.rollback();
return;
}

wysota
20th August 2013, 11:28
QTranslator qtTrans;
qtTrans.load("qt_pt.qm");
app.installTranslator(&qtTrans);

// ...

int r = QMessageBox::question(this, tr("Delete CD"), tr("delete \"%1\" and all its tracks?")
.arg(record.value(cd_idartista).toString()),
QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape);

Cupidvogel
21st June 2015, 00:51
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?