如何在QML中设置MessageDialog的默认按钮? [英] How to set the default button of a MessageDialog in QML?

查看:38
本文介绍了如何在QML中设置MessageDialog的默认按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认按钮为是",但我想将按钮否"设置为默认按钮.

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

该怎么做?

推荐答案

我看不到通过当前的 MessageDialog API实现此目的的任何方法,但我也可以想象,这非常很多平台特定的,这就是为什么它是隐藏的.

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

这篇关于如何在QML中设置MessageDialog的默认按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆