Add support for custom button labels to Qt wxMessageDialog

Just set the label if it's specified.
This commit is contained in:
Vadim Zeitlin 2024-02-11 13:53:24 +01:00
parent f3260b3b16
commit 09fe965219

View file

@ -14,6 +14,7 @@
#include "wx/qt/private/winevent.h"
#include <QtWidgets/qmessagebox.h>
#include <QtWidgets/qpushbutton.h>
class wxQtMessageDialog : public wxQtEventSignalHandler< QMessageBox, wxMessageDialog >
@ -102,14 +103,20 @@ void wxQtMessageDialog::InitializeIfNeeded(wxMessageDialog& msgdlg)
// Buttons
const long style = msgdlg.GetMessageDialogStyle();
const auto applyCustomLabelIfSet = [](QPushButton* button, const wxString& label)
{
if ( !label.empty() )
button->setText( wxQtConvertString( label ) );
};
if ( style & wxOK )
addButton( QMessageBox::Ok );
applyCustomLabelIfSet(addButton( QMessageBox::Ok ), msgdlg.GetOKLabel());
if ( style & wxCANCEL )
addButton( QMessageBox::Cancel );
applyCustomLabelIfSet(addButton( QMessageBox::Cancel ), msgdlg.GetCancelLabel());
if ( style & wxYES_NO )
{
addButton( QMessageBox::Yes );
addButton( QMessageBox::No );
applyCustomLabelIfSet(addButton( QMessageBox::Yes ), msgdlg.GetYesLabel());
applyCustomLabelIfSet(addButton( QMessageBox::No ), msgdlg.GetNoLabel());
}
// Default button