Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Constructor arguments of QKeyEvent ?
Forum Updated to NodeBB v4.3 + New Features

Constructor arguments of QKeyEvent ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.8k Views 3 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    Hello,
    I must implement a simple virtual keyboard. It is not all clear for me how to do it. Buttons/Layout etc. is simple but how to send the keys.
    Here some code examples:

    QWidget * w = QApplication::focusWidget();
       if(!w)
           return;
       QKeyEvent e(QEvent::KeyPress, Qt::Key_X,Qt::NoModifier, "ab");
       QApplication::sendEvent(w, &e);
       QKeyEvent e2(QEvent::KeyRelease, Qt::Key_A,Qt::NoModifier, "a");
       QApplication::sendEvent(w, &e2);
    

    Unclear is the constructor of QKeyEvent. Why argument 2 AND argument 4.
    Argument 2 should describe the key. For what is argument 4. I found that this string (multiple chars) will be send to the input widget and I must set here a string which is independent of argument 2. For what is argument 2 then ?
    Second question is: Must I send a keyrelease for proper working of the virtual keyboard.
    Any other tips for a developing a virtual keyboard are welcome, too.

    mrjjM 1 Reply Last reply
    0
    • Andy314A Andy314

      Hello,
      I must implement a simple virtual keyboard. It is not all clear for me how to do it. Buttons/Layout etc. is simple but how to send the keys.
      Here some code examples:

      QWidget * w = QApplication::focusWidget();
         if(!w)
             return;
         QKeyEvent e(QEvent::KeyPress, Qt::Key_X,Qt::NoModifier, "ab");
         QApplication::sendEvent(w, &e);
         QKeyEvent e2(QEvent::KeyRelease, Qt::Key_A,Qt::NoModifier, "a");
         QApplication::sendEvent(w, &e2);
      

      Unclear is the constructor of QKeyEvent. Why argument 2 AND argument 4.
      Argument 2 should describe the key. For what is argument 4. I found that this string (multiple chars) will be send to the input widget and I must set here a string which is independent of argument 2. For what is argument 2 then ?
      Second question is: Must I send a keyrelease for proper working of the virtual keyboard.
      Any other tips for a developing a virtual keyboard are welcome, too.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Andy314

      Hi
      I would seek inspiration in existing implementations
      like
      https://www.linux-apps.com/p/1132203/

      Andy314A 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        The QKeyEvent constructor documentation explains all the parameters.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        4
        • mrjjM mrjj

          @Andy314

          Hi
          I would seek inspiration in existing implementations
          like
          https://www.linux-apps.com/p/1132203/

          Andy314A Offline
          Andy314A Offline
          Andy314
          wrote on last edited by Andy314
          #4

          Hello @mrjj ,
          as a inspiration it is good.
          They use an other concept, in the close sense it is not really a virtual keyboard. It works only with a QLineEdit (and its subclasses) and sends keystrokes never but rather manipulates the QLineEdit::text directly.

          In general I dont understand, why I must send a keystroke to a special widget with the following code (I in my code I look for the focused.)
          QApplication::sendEvent(wiget, &event);
          This works only for Qt-Apps. Why can I not send a key to the operating system and the system processes it relating to its rules ?

          mrjjM 1 Reply Last reply
          0
          • Andy314A Andy314

            Hello @mrjj ,
            as a inspiration it is good.
            They use an other concept, in the close sense it is not really a virtual keyboard. It works only with a QLineEdit (and its subclasses) and sends keystrokes never but rather manipulates the QLineEdit::text directly.

            In general I dont understand, why I must send a keystroke to a special widget with the following code (I in my code I look for the focused.)
            QApplication::sendEvent(wiget, &event);
            This works only for Qt-Apps. Why can I not send a key to the operating system and the system processes it relating to its rules ?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Andy314
            Oh, sorry I thought it would be more clever made.
            To send events to the OS, you need to use native API.

            Qt has support for handling the virtual keyboard
            http://doc.qt.io/qt-4.8/qt-tools-inputpanel-example.html
            notice the QEvent::RequestSoftwareInputPanel
            I have not tested these on Desktop but Docs seems not to limit use.

            If you want to make a native virtual keyboard that work with ANY app, you need to dive into the native app for that.

            1 Reply Last reply
            1

            • Login

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