How to set the default button of a MessageDialog i

2019-07-24 03:11发布

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

How to do it?

1条回答
狗以群分
2楼-- · 2019-07-24 03:48

I don't see any way to achieve this through the current MessageDialog API, but I'd also imagine that this is very much platform-specific, and that's why it's hidden.

You can make your own dialog, though:

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

查看更多
登录 后发表回答