首页 > 解决方案 > 如何让用户使用 control + + 进行放大和 control + - 进行缩小?

问题描述

我下面的代码的问题是,在美国/英国键盘布局+是用 生成的shift + =,但是当用户同时使用 control 和 shift 修饰符时,+不会生成。这已经在 Mac 上测试过了。

    Keys.onPressed: {
        if (event.modifiers & Qt.ControlModifier) {
            if (event.key === Qt.Key_Minus) {
                zoom(false)
                event.accepted = true
            } else if (event.key === Qt.Key_Plus) {
                zoom(true)
                event.accepted = true
            }
        }
    }

由于control + +control + -是放大应用程序的标准快捷方式,我确信其他人已经解决了这个问题。但是怎么做?

标签: qtqml

解决方案


而不是Key.onPresseduseShortcut及其sequence属性

Shortcut {
    sequence: StandardKey.ZoomIn
    onActivated: zoom(true)
}

QKeySequence 文档的这一部分提到了您的问题。


推荐阅读