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?
Forum Updated to NodeBB v4.3 + New Features

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 2 Watching
  • 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.
  • M Offline
    M Offline
    MasterBLB
    wrote on 29 Jul 2021, 09:15 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

    C 1 Reply Last reply 29 Jul 2021, 10:50
    0
    • M MasterBLB
      29 Jul 2021, 09:15

      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

      C Offline
      C Offline
      CP71
      wrote on 29 Jul 2021, 10:50 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
      • M Offline
        M Offline
        MasterBLB
        wrote on 30 Jul 2021, 08:57 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

        1/3

        29 Jul 2021, 09:15

        • Login

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