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 to get access to QKeyEvent(not KeyEvent) in QML?

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 285 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.
  • MasterBLBM Offline
    MasterBLBM Offline
    MasterBLB
    wrote on last edited by
    #1

    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

    CP71C 1 Reply Last reply
    0
    • MasterBLBM MasterBLB

      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

      CP71C Offline
      CP71C Offline
      CP71
      wrote on last edited by
      #2

      @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
      0
      • MasterBLBM Offline
        MasterBLBM Offline
        MasterBLB
        wrote on last edited by
        #3

        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
        0

        • Login

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