问题描述
我下面代码的问题是,在美国/英国键盘布局上,+
是使用 shift + =
生成的,但是当用户同时使用 control 和 shift 修饰符时同时,+
不会生成.这已经在 Mac 上测试过了.
The problem with my code below is that on US/UK keyboard layouts +
is generated with shift + =
, but when the user uses both the control and shift modifiers simultaneously, +
is not generated. This has been tested on 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 + -
是放大应用程序的标准快捷方式,我确信其他人已经解决了这个问题.但是怎么做呢?
Since control + +
and control + -
are standard shortcuts for zooming in applications I am certain that others have solved this. But how?
推荐答案
使用 及其 sequence
属性 :
Instead of Key.onPressed
use Shortcut
and its sequence
property :
Shortcut {
sequence: StandardKey.ZoomIn
onActivated: zoom(true)
}
本节中提到了您的问题的 QKeySequence 文档.
Your issue is mentionned in this section of the QKeySequence documentation.
这篇关于如何让用户使用 control + + 进行放大和 control + - 进行缩小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!