Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How can I let users use control + + for zoom in and control + - for zoom out?

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 623 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pokemonsrqt
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      2
      • GrecKoG GrecKo

        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.

        P Offline
        P Offline
        pokemonsrqt
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved