PDA

View Full Version : Add virtual keyboard to window using QWidget's "Promote to" feature?



Leutzig
29th April 2016, 12:48
Hi,

I'm interested in adding a virtual keyboard to my application. I found this virtual keyboard that I want to use but I need to open it inside my application instead of opening it in a separate window. To do this I've added the header + source file to my project, added an empty widget to my UI and promoted it to the keyboard class. This gives me the following errors:



/home/stud/devel/build-keyboardTest-Desktop-Debug/ui_keyboardtest.h:30: error: 'keyboard' does not name a type
keyboard *widget;
^



/home/stud/devel/build-keyboardTest-Desktop-Debug/ui_keyboardtest.h:42: error: 'widget' was not declared in this scope
widget = new keyboard(centralWidget);
^



/home/stud/devel/build-keyboardTest-Desktop-Debug/ui_keyboardtest.h:42: error: expected type-specifier before 'keyboard'
widget = new keyboard(centralWidget);
^

I'm able to open the keyboard in a separate window, but this doesn't work. Also promote widget calls the constructor that takes only QWidget*, so the "Promote to" feature might not be an option for my classes that take more than QWidget* in the constructor. How can I do this in that case?

The virtual keyboard is found here:
https://www.kdab.com/qt-input-method-virtual-keyboard/

Source code:
https://github.com/KDAB/virtual-keyboard-demo/tree/master/server

yeye_olive
29th April 2016, 15:14
/home/stud/devel/build-keyboardTest-Desktop-Debug/ui_keyboardtest.h:30: error: 'keyboard' does not name a type
keyboard *widget;
^
Look at line 6 in keyboard.h. All three errors will vanish once you fix this one.


Also promote widget calls the constructor that takes only QWidget*, so the "Promote to" feature might not be an option for my classes that take more than QWidget* in the constructor. How can I do this in that case?
You can't. That is the limit of promotion: by sticking to the basic QWidget interface, you cannot expect Designer to do anything that a QWidget cannot do. I strongly recommend that every widget class have at least a (QWidget *) constructor that does the default setup, and methods to alter this setup after construction.

Leutzig
30th April 2016, 00:40
Thanks, I realized that keyboard should be written with a capital "K" everywhere, and the errors were gone. Now I'm a bit confused as to why my virtual keyboard opens in a separate window when I'm using promotion. In keyboard's constructor I set the visibility to true and if I resize the empty widget, the size of the virtual keyboard changes (opened separately).

11915

d_stranz
30th April 2016, 21:28
Have you added this new Keyboard instance to a layout inside your "central widget" (whatever that is)? Is "central widget" non-NULL?

yeye_olive
30th April 2016, 23:21
The keyboard is a separate window because it is configured as a tool window. Its constructor calls QWidget::setWindowFlags() and passes the Qt::Tool flag. You should try removing this line entirely.

Leutzig
30th April 2016, 23:29
Yea that was it. Looks good now. Thanks a lot for the help.

// Leutzig