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. QML Key event Qt.key_Minus can't used

QML Key event Qt.key_Minus can't used

Scheduled Pinned Locked Moved Solved QML and Qt Quick
key eventqt.keyminus
6 Posts 2 Posters 2.6k 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.
  • N Offline
    N Offline
    neng
    wrote on 29 Apr 2016, 02:43 last edited by p3c0
    #1

    I run some .qml file with qmlscene, but key event Qt.key_Plus has no effect, and when I pressed Qt.key_Minus several times, the GreenSquare became larger, Qt version: 5.6.0, OS: redhat 6/ubuntu.
    Codes:
    keys.qml:

    import QtQuick 2.0
    
    DarkSquare {
        width: 400; height: 200
    
        GreenSquare {
            id: square
            x: 8; y: 8
        }
    
        focus: true
        Keys.onLeftPressed: square.x -= 8
        Keys.onRightPressed: square.x += 8
        Keys.onUpPressed: square.y -= 8
        Keys.onDownPressed: square.y += 8
        Keys.onPressed: {
            switch (event.key) {
            case Qt.Key_Plus:
                square.scale += 0.2
                break;
            case Qt.Key_Minus:
                square.scale -= 0.2
                break;
            }
        }
    }
    

    DarkSquare.qml:

    import QtQuick 2.0
    
    Rectangle {
        width: 48
        height: 48
        color: "black"
        border.color: Qt.darker(color)
    }
    

    GreenSquare.qml:

    import QtQuick 2.0
    
    DarkSquare {
        width: 48
        height: 48
        color: "green"
        border.color: Qt.lighter(color)
    }
    

    What can I do to avoid this bug, or fix this bug?

    M 1 Reply Last reply 29 Apr 2016, 13:15
    0
    • N neng
      29 Apr 2016, 02:43

      I run some .qml file with qmlscene, but key event Qt.key_Plus has no effect, and when I pressed Qt.key_Minus several times, the GreenSquare became larger, Qt version: 5.6.0, OS: redhat 6/ubuntu.
      Codes:
      keys.qml:

      import QtQuick 2.0
      
      DarkSquare {
          width: 400; height: 200
      
          GreenSquare {
              id: square
              x: 8; y: 8
          }
      
          focus: true
          Keys.onLeftPressed: square.x -= 8
          Keys.onRightPressed: square.x += 8
          Keys.onUpPressed: square.y -= 8
          Keys.onDownPressed: square.y += 8
          Keys.onPressed: {
              switch (event.key) {
              case Qt.Key_Plus:
                  square.scale += 0.2
                  break;
              case Qt.Key_Minus:
                  square.scale -= 0.2
                  break;
              }
          }
      }
      

      DarkSquare.qml:

      import QtQuick 2.0
      
      Rectangle {
          width: 48
          height: 48
          color: "black"
          border.color: Qt.darker(color)
      }
      

      GreenSquare.qml:

      import QtQuick 2.0
      
      DarkSquare {
          width: 48
          height: 48
          color: "green"
          border.color: Qt.lighter(color)
      }
      

      What can I do to avoid this bug, or fix this bug?

      M Offline
      M Offline
      medyakovvit
      wrote on 29 Apr 2016, 13:15 last edited by
      #2

      @neng
      If you mean that size of rectangle increased after scale become < 0, then Item.scale

      A scale of less than 1.0 causes the item to be rendered at a smaller size, and a scale greater than 1.0 renders the item at a larger size. A negative scale causes the item to be mirrored when rendered.
      
      1 Reply Last reply
      0
      • N Offline
        N Offline
        neng
        wrote on 3 May 2016, 08:02 last edited by
        #3

        Thank you for the reply!
        but key event Qt.key_Plus has no effect, mybe I need to change the key instead of Qt.key_plus to enlarge the target.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          neng
          wrote on 3 May 2016, 08:20 last edited by
          #4

          I Use Qt.key_0 to enlarge the rectangle, the rectangle is enlarged successfully, I think it's qt quick's bug.

          M 1 Reply Last reply 3 May 2016, 19:41
          0
          • N neng
            3 May 2016, 08:20

            I Use Qt.key_0 to enlarge the rectangle, the rectangle is enlarged successfully, I think it's qt quick's bug.

            M Offline
            M Offline
            medyakovvit
            wrote on 3 May 2016, 19:41 last edited by
            #5

            @neng said:

            Is Keys.onPressed executed when you press "+"? And if yes, what the value of event.key?

            1 Reply Last reply
            0
            • N Offline
              N Offline
              neng
              wrote on 4 May 2016, 01:06 last edited by
              #6

              Thanks, it's my problem.
              If you need event Qt.key_plus, you must press Shift and =, else if you press =, the event is Qt::Key_Equal.

              1 Reply Last reply
              0

              3/6

              3 May 2016, 08:02

              • Login

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