4

I have in my main.qml the following code

 MessageDialog {
    id: exitDialog
    title: "Quit"
    text: "Save before quitting?"
    icon: StandardIcon.Question
    standardButtons: StandardButton.Save| StandardButton.Discard |  StandardButton.Cancel
    onAccepted: {
    ...
    }
    onDiscard: Qt.quit()
}

The problem however is the buttons for me appear as close without Saving Cancel and last Save! The default button is set as close without saving. I want my order of buttons in the code maintained and also default set as save. Anyone face such problems? any suggestions ?

I have seen this answer How to set the default button of a MessageDialog in QML? but how do I do it for standardButtons?

Community
  • 1
  • 1

1 Answers1

1

Just to give an idea. http://doc.qt.io/qt-5/qmessagebox.html

The display order for the buttons is platform-dependent. For example, on Windows, Save is displayed to the left of Cancel, whereas on Mac OS, the order is reversed.

Mark one of your standard buttons to be your default button.

QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
9T9
  • 698
  • 2
  • 9
  • 22