qt - 如何让用户使用 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 + -
是放大应用程序的标准快捷方式,我确信其他人已经解决了这个问题。但是怎么做?
解决方案
而不是Key.onPressed
useShortcut
及其sequence
属性:
Shortcut {
sequence: StandardKey.ZoomIn
onActivated: zoom(true)
}
QKeySequence 文档的这一部分提到了您的问题。
推荐阅读
- c++ - C++ OPENCV 4.3.0 x64 为什么 face_cascade 会抛出错误?
- javascript - 如何从 javascript 中的警报弹出窗口中复制和粘贴文本?
- python - 我将如何删除精灵?
- python - 生成对抗网络的“反向”NLLLoss 中的实际不确定性
- python - 如何在linux中使用cdo合并多个nc文件
- linux - Docker 容器中的 Docker 未映射 .ssh 卷
- cpu - 如何释放在 halide 中定义的 CPU 缓冲区
- laravel - 如何从 laravel 7 的资源文件夹中链接 js 文件
- python - 托管在 heroku 上的 discord.py 机器人不会上线
- html - 在以下表格中,如何增加输入支架的长度以使我的表格看起来密集?