How to make a widget like user control?
-
wrote on 19 May 2016, 09:06 last edited by
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) -
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 ?
-
@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.
wrote on 21 May 2016, 04:23 last edited by MhM93I made a keyboard widget and promoting it to other widget. But how can I access the parent widget and change the data by press each button in keyboard widget?
-
That's not a good idea. You should rather take a look at the Input Panel example
-
That's not a good idea. You should rather take a look at the Input Panel example
1/7