How can I let users use control + + for zoom in and control + - for zoom out?

前端 未结 2 1464
醉梦人生
醉梦人生 2021-01-26 07:09

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 modif

相关标签:
2条回答
  • 2021-01-26 07:46

    You have to use Qt.ShiftModifier for reacting on shift key:

    Item {
        focus: true
        Keys.onPressed: {
            if ((event.key == Qt.Key_Plus) && (event.modifiers & Qt.ShiftModifier))
                console.log("PRessed");
        }
    }
    
    0 讨论(0)
  • 2021-01-26 07:56

    Instead of Key.onPressed use Shortcut and its sequence property :

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

    Your issue is mentionned in this section of the QKeySequence documentation.

    0 讨论(0)
提交回复
热议问题