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. Virtual Keyboard logic?
Qt 6.11 is out! See what's new in the release blog

Virtual Keyboard logic?

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

    Hello,

    I am new to Qt and making a personal application using PySide2.

    I want a virtual keyboard on my application as I am putting it on the Raspberry Pi.

    I have designed a simple numpad as I only need numbers.

    Problem is that I have never done this before and don't know the logic to use for it.

    Like there are 5 single line entry input boxes. I will tap on first one, then press a number on the virtual numpad. But what is the logic that I should implement on the button?

    My current thinking is that I will get the current cursor position and insert a number there but won't tapping a button change the current cursor location?

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

      Hi and welcome to devnet,

      You should read about the Qt input method:

      • https://www.kdab.com/qt-input-method-depth/
      • https://www.kdab.com/qt-input-method-virtual-keyboard/

      They give a pretty good overview on how to implement a virtual keyboard for Qt.

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

      L 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        You should read about the Qt input method:

        • https://www.kdab.com/qt-input-method-depth/
        • https://www.kdab.com/qt-input-method-virtual-keyboard/

        They give a pretty good overview on how to implement a virtual keyboard for Qt.

        L Offline
        L Offline
        lolcocks
        wrote on last edited by
        #3

        @SGaist

        @SGaist said in Virtual Keyboard logic?:

        Hi and welcome to devnet,

        You should read about the Qt input method:

        • https://www.kdab.com/qt-input-method-depth/
        • https://www.kdab.com/qt-input-method-virtual-keyboard/

        They give a pretty good overview on how to implement a virtual keyboard for Qt.

        Ummmm, quick question, does PySide2 have a implementation of these virtual keyboards?

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

          Do you mean a version of the example from KDAB translated to python ?

          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
          1
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Hi
            Im not sure if you ask about the Qt virtual keyboard or just a homemade mini version.

            But what is the logic that I should implement on the button?

            For a homemade very simple keyboard, you should
            Flag all buttons with NoFocus ( setFocusPolicy )
            So they don't steal the keyboard focus from the current selected Widget
            when you click a keyboard button.

            Then you can use
            QWidget * widgetName = qApp->focusWidget();

            To find out which another widget the keyboard should type into.

            Then use sendEvent to send key presses to the selected widget

            QKeyEvent event1(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, "a");
            QKeyEvent event2(QEvent::KeyRelease, Qt::Key_A, Qt::NoModifier);
            QApplication::sendEvent(widgetName , &event1);
            QApplication::sendEvent(widgetName , &event2);
            

            make sure to send both key up/down as a normal key would.

            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