Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • The problem is that + and - share keys with different characters on different keyboard language layouts. On some layouts a shift modifier is required to generate the + sign, but when the control modifier is pressed, the shift modifier seems to have no effect.

    The code below for example works on a Swedish keyboard layout, but not on US/UK keyboard layouts where the + is generated with shift + =.

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

    This has been tested on Mac.

    I would like to find a general solution that works on all keyboard layouts.


  • Qt Champions 2018

    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.



  • This post is deleted!

Log in to reply