Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved How to get access to QKeyEvent(not KeyEvent) in QML?

    QML and Qt Quick
    2
    3
    122
    Loading More Posts
    • 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.
    • MasterBLB
      MasterBLB last edited by

      Hey Mates

      I need hints how to get passed QKeyEvent* for such code:

      class Internals : public QObject
      {
          Q_OBJECT
          QML_ANONYMOUS
      
      public:
          explicit Internals(QObject *parent = nullptr);
      
      private slots:
          void emissionTest();//this just emits keyReleased with freshly created QKeyEvent 3s after instantiating Internals
      
      signals:
          void keyReleased(QKeyEvent *e);
          void longKeyPress(QKeyEvent *e);
      };
      
      class Navigation : public QObject
      {
          Q_OBJECT
          QML_ATTACHED(Internals)
      
      public:
          explicit Navigation(QObject *parent = nullptr);
      
          static Internals* qmlAttachedProperties(QObject *object)
          {
              return new Internals(object);
          }
      };
      
      //and somewhere in QML:
      Window
      {
          id: mainWindow
      
          Navigation.onKeyReleased:
          {
              console.log("Works! Key code: " + I'd like to get QKeyEvent here)
          }
      }
      

      Regards,
      MasterBLB

      CP71 1 Reply Last reply Reply Quote 0
      • CP71
        CP71 @MasterBLB last edited by

        @MasterBLB
        Hi,
        sorry I'm not QML developer, so more I can't help you.

        Maybe this can help you:
        https://doc.qt.io/qt-5/qml-qtquick-keys.html

        1 Reply Last reply Reply Quote 0
        • MasterBLB
          MasterBLB last edited by

          Sadly, that Keys are related to KeyEvent, which I can't use - well, unless it's possible in QML to inherit and alter a class like KeyEvent. But if I understand documentation correctly it is not.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post