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. handle KeyEvent in C++
QtWS25 Last Chance

handle KeyEvent in C++

Scheduled Pinned Locked Moved Solved QML and Qt Quick
keyeventqkeyevent
3 Posts 2 Posters 1.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.
  • B Offline
    B Offline
    BePie
    wrote on last edited by
    #1

    With a c++ class that has a slot

    void handleKeyEvent(QKeyEvent event);
    // or
    void handleKeyEvent(QKeySequence event);
    

    I can only use (inside qml) QKeySequence version of the slot given event from Keys.pressed. Sadly, this results in an empty sequence (QKeySequence::toString() gives an empty string).

    How one can handle those KeyEvents in a c++ class?

    T 1 Reply Last reply
    0
    • B BePie

      With a c++ class that has a slot

      void handleKeyEvent(QKeyEvent event);
      // or
      void handleKeyEvent(QKeySequence event);
      

      I can only use (inside qml) QKeySequence version of the slot given event from Keys.pressed. Sadly, this results in an empty sequence (QKeySequence::toString() gives an empty string).

      How one can handle those KeyEvents in a c++ class?

      T Offline
      T Offline
      Tirupathi Korla
      wrote on last edited by
      #2

      @BePie
      inherit QQuickview and override keypressEvent

      class MyQuickView : public QQuickView{
      public:
      void keyPressEvent(QKeyEvent * event){
      }
      }

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BePie
        wrote on last edited by
        #3

        thanks,

        I missed it because I usually used QQmlEngine or something alike and not a QQuickView.

        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