How to set default MessageDialog button in QML?

The default button is Yes, but I want to set the No button as the default button.

How to do it?

+2
source share
1 answer

I do not see any way to achieve this using the current API MessageDialog, but I also assume that this is very platform specific and why it is hidden.

You can create your own dialog:

import QtQuick 2.3
import QtQuick.Window 2.0
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2

Window {
    width: 500
    height: 500
    visible: true

    Dialog {
        id: dialog
        visible: true

        contentItem: FocusScope {
            Row {
                anchors.bottom: parent.bottom
                anchors.right: parent.right

                Button {
                    text: "No"
                    isDefault: true
                    focus: true
                    onClicked: dialog.close()
                }
                Button {
                    text: "Yes"
                }
            }
        }
    }
}

dialog

+4
source

Source: https://habr.com/ru/post/1649373/


All Articles