Unsolved Virtual Keyboard logic?
-
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?
-
Hi and welcome to devnet,
You should read about the Qt input method:
They give a pretty good overview on how to implement a virtual keyboard for Qt.
-
@SGaist said in Virtual Keyboard logic?:
Hi and welcome to devnet,
You should read about the Qt input method:
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?
-
Do you mean a version of the example from KDAB translated to python ?
-
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.