Solved Problem with setButtonText on QMessageBox - Android
-
Hi.
I have a problem with QMessageBox, the property setButtonText not change text of default button yes/no to my language, in this case pt_BR.
When execute, applications on all devices Android show [YES] [NO] instead [SIM] [NÃO].This is my code:
QMessageBox *msg = new QMessageBox(this); msg->setText("Deseja cancelar ?"); msg->setStandardButtons(QMessageBox::Yes |QMessageBox::No); msg->setButtonText(QMessageBox::Yes, "Sim"); msg->setButtonText(QMessageBox::No, "Não"); msg->exec();
Thanks.
-
@joaopagotto See http://doc.qt.io/qt-5/qmessagebox-obsolete.html
The following members of class QMessageBox are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.
You should use http://doc.qt.io/qt-5/qmessagebox.html#addButton instead.
-
Well. I try follow your tip, but doesn't work.
See my code and screenshots below.
Can it be bug in the Qt libraries for Android ?This my code:
QMessageBox msg; msg.setText("Deseja cancelar ?"); msg.addButton("Sim", QMessageBox::YesRole); msg.addButton("Nao", QMessageBox::NoRole); msg.exec();
On Windows MSVC2015-x32
On Android arm7 6.0
This code sample in QMessageBox doc, but button "Connect" doesn't appear, only Abort Button:
QMessageBox msgBox; QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole); QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort); msgBox.exec();
-
@joaopagotto What Qt version do you use?
-
@jsulm Qt 5.7.0 and Qt 5.7.1 same problem.
-
@joaopagotto Could be that it is not supported on Android. Maybe anybody else knows?
-
AFAIK, Qt is not provided it on Android native style except default buttons.
If you want to use the Qt style, try this:qputenv("QT_USE_ANDROID_NATIVE_DIALOGS", "0");
-
@Devopia53 this works very well ! Thank you so much ! =D