How to set the default button of a MessageDialog in QML?

烈酒焚心 提交于 2019-12-11 03:58:28

问题


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

How to do it?


回答1:


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"
                }
            }
        }
    }
}



来源:https://stackoverflow.com/questions/29960414/how-to-set-the-default-button-of-a-messagedialog-in-qml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!