How to make a widget like user control?
-
I make a keyboard for my embedded device that just have numbers keys.
I have some forms( widgets) that contains multi text boxes. I want to call my keyboard widget in my forms.(not to copy paste all the buttons and all the signals and all the slots)
How can I define my keyboard widget?
How can I use it in my all forms?(like a button control) -
@MhM93
I would make the keyboard widget post the appropriate key events, for example:QWidget * widget = QApplication::focusWidget(); if (widget) { // 0 was pressed QCoreApplication::postEvent(widget, new QKeyEvent(QEvent::KeyPress, Qt::Key_0)); QCoreApplication::postEvent(widget, new QKeyEvent(QEvent::KeyRelease, Qt::Key_0)); }
You could improve on that if you keep the
widget
variable throughout the application and intercept the focus changed events, so you don't need to always get the focused widget from the application.Kind regards.
-
Hi,
What version of Qt are you using ?
What about making it a virtual keyboard ?
-
That's not a good idea. You should rather take a look at the Input Panel example