PDA

View Full Version : virtual keyboard in QT Application



vinithr
29th May 2012, 09:38
hi,

I am trying to create a simple Qt application which is used virtual keyboard to enter data to a lineedt.

Could you please help me out to integrate the virtual keyboard to Qt ?

Thanks in Advance.

Regards
Vinithr

aamer4yu
29th May 2012, 11:59
You have your own virtual keyboard ? Or how do you plan to use it ?
Well you can show a custom widget as a virtual keyboard. You will need to derive your own class from QInputContext.
In the filterEvent you can show the input panel.

You will also need to set the input context to your application QApplication::setInputContext

There was also some Qt example related to input context. You can search for it too.

vinithr
29th May 2012, 12:09
Thanks for your reply..

Well i am planning to use full keyboard only. I found the input panel that have numbers only.

I dont have any virtual keyboard application. Could you please help me out to trace the application.

And i would like to know, which will be better, a custom widget or a input panel.??


Looking forward for your reply...


Regards
vinithr

aamer4yu
29th May 2012, 12:37
Kindly also google little...
A little search would have given you these -
http://qt-project.org/doc/qt-4.8/tools-inputpanel.html
http://labs.qt.nokia.com/2009/08/31/new-api-for-input-panel-virtual-keyboards/

Lesiok
29th May 2012, 14:40
Look at this link (http://qt-apps.org/content/show.php/VirtualKeyboard?content=107388)

StrikeByte
4th June 2012, 08:19
I've attached my code for a virtual keyboard (see 7795)
at the moment it only works for qlineedit but it is easy to change it for other inputs
password input is supported

sorry documentation is missing and the chaos in the code

this is how to use it:
* make an instance of the input device in your main after doing this it is working (InputDevice *inputdevice = new InputDevice; //start the keyboard)
* add a custom property to a QLineEdit and call it keyboard and set it to true (this enables the keyboard for the lineedit)
* optionally add a custom property inputType set it to REAL or INT for the numpad type any other value will be handled as string and starts the keyboard

i hope it will help u create your own keyboard or use it as is

sonulohani
7th June 2012, 12:34
OK create one keyboard and create an instance of it in your class and use it. Or simple is that create one lineedit with keyboard having pushbuttons. and connect all the push button to your lineEdit. If you want to use your keyboard in differents gui then you have to create a different class for keyboard. if you want some help in keyboard tutorial then you're welcome to query.

vinithr
10th June 2012, 13:09
Thanks for your help..

StrikeByte
11th June 2012, 09:36
I've changed the keyboard to now also be able to use QValidator instead of the custom property inputType
if you add a QDoubleValidator or QIntValidator to your lineedit it shows the numberic editor and also checks the value
download the new version 7833

newzen
12th January 2013, 11:35
StrikeByte thanks for share your work. Could you provide application example for use provided inputDevice. Thanks in advance

Veerapandian
7th May 2013, 13:39
Hi Experts,
Do you have any idea about how to add virtual keyboard support in QT browser (Example Fancy browser)?
If i click the loaded webpage text input field (example "google search" input box in the google web site) virtual keyboard should be pop up.
Any idea?

if you have any code means please share it here...

Thanks in advance,
Veera

wysota
7th May 2013, 21:46
Implement an input context plugin.

StrikeByte
26th February 2014, 11:08
here is a new version, this only contains some fixes 10083

Howto use:
main.cpp


#include <QApplication>
#include "inputdevice.h"

int main(int argc, char *argv[])
{
QApplicationa(argc, argv);
InputDevice inputdevice;

//here the code for forms or something else

return a.exec();
}


code for enabling keyboard on a lineedit



aLineEdit->setProperty("keyboard",true); //enable the keyboard (this is a custom property)
aLineEdit->setValidator(QIntValidator(0,500)); //add a int validator min value 0 max value 500. This will force the numpad to show, you can also use a QDoubleValidator

aTextLineEdit->setProperty("keyboard",true); // enable the keyboard. when there is no validator set the keyboard will show
//aTextLineEdit->setProperty("maxLength",25); //this can be used to limit the length of the string

//it is also possible to set the properties in QT designer

Piergiogio
16th March 2014, 07:58
Hello,

Thanks for your example, it is very useful. In Qt5 does not work because does not finds #include <QInputContext>
Do you have a idea?

Thanks

anda_skoa
16th March 2014, 09:43
In Qt5 this is handled as part of the platform integration plugin (QPA).

qtbase/src/plugins/platforms

Cheers,
_

Mumymania
2nd July 2014, 16:43
here is a new version, this only contains some fixes 10083

Howto use:
main.cpp


#include <QApplication>
#include "inputdevice.h"

int main(int argc, char *argv[])
{
QApplicationa(argc, argv);
InputDevice inputdevice;

//here the code for forms or something else

return a.exec();
}


code for enabling keyboard on a lineedit



aLineEdit->setProperty("keyboard",true); //enable the keyboard (this is a custom property)
aLineEdit->setValidator(QIntValidator(0,500)); //add a int validator min value 0 max value 500. This will force the numpad to show, you can also use a QDoubleValidator

aTextLineEdit->setProperty("keyboard",true); // enable the keyboard. when there is no validator set the keyboard will show
//aTextLineEdit->setProperty("maxLength",25); //this can be used to limit the length of the string

//it is also possible to set the properties in QT designer


Hello,

When I'm trying to include your code as per the previous instructions I get the following errors:
undefined reference to `Numpad::activate(QVariant, QValidator const*)'
undefined reference to `Numpad::setEchoMode(QLineEdit::EchoMode)'
undefined reference to `Keyboard::activate(QVariant, int, bool)'
undefined reference to `Keyboard::setValidator(QValidator const*)'

Could you please point out to me what the problem is? :)

Best regards

aamer4yu
3rd July 2014, 09:43
You can refer to this (http://www.qtcentre.org/threads/55428-Qt5-custom-input-contexts-gone-How-to-convert-from-Qt4-QInputContext) thread.

Hope it helps :)

StrikeByte
3rd February 2015, 10:00
It's a while ago that I made InputDeviceV3.zip, but didn't have a need to build a new one up until now,
now I needed a virtual input for Qt5.3 so I made the InputDevice working again.
I didn't do any major changes (only the name), it still only works for QLineEdits
Here is the download:
10939

How to use:

Build the library
copy the library to platforminputcontexts in your application or to plugins/platforminputcontexts in your QtDir
Add a custom property named "keyboard" (without the quotes) of the type bool to the QLineEdit and set it to enabled
For text you can set the maxLength property
For values you can add a QIntValidator to the QLineEdit

srm
22nd March 2015, 21:33
Hi, thanks for the update.
I'm pretty new to Qt (and to C++) and I'm having trouble using your project. Running Qt-Creator 3.3.0 and Qt5.4.
I can open your project, but compiling it yields errors.

numpad.cpp:166:18: error: taking the address of a temporary object of type 'QVariant' [-Waddress-of-temporary]
emit dataSet(&QVariant(ui->edValue->text()));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
numpad.cpp:189:33: error: non-const lvalue reference to type 'QString' cannot bind to a temporary of type 'QString'
if (validator->validate(ui->edValue->text(),pos) == QValidator::Acceptable)
^~~~~~~~~~~~~~~~~~~
/Users/srm/Development/Qt/5.4/clang_64/lib/QtGui.framework/Headers/qvalidator.h:67:37: note: passing argument to parameter here
virtual State validate(QString &, int &) const = 0;
^

This was running qmake && make in the project dir.
What am I doing wrong? Do you need any more information?

EDIT: running on OSX 10.10.2

StrikeByte
23rd March 2015, 08:16
I made the project on a windows machine and a visual studio compiler. It looks like the compiler you are using won't allow temp variables in function calls
I don't have a mac to try it on.
Mabe you can find more when googling the error description (QString' cannot bind to a temporary of type 'QString) or start a thread in the newbe section of the forum.

anda_skoa
23rd March 2015, 09:04
Instead of taking the address of a temporary QVariant, make it a local variable and take its address.

In the second error, you are required to pass a reference to a QString. You are trying to pass the return value of a function, which is also a temporary.
Again, make a local variable, initialiize it with the result of the function and then pass the variable to the validate method.

Cheers,
_

srm
24th March 2015, 22:28
Thanks for the pointers. I was able to fix the error messages as per your suggestion.
For example

emit dataSet(&QVariant(ui->edValue->text()));
became

QVariant qv = QVariant(ui->edValue->text());
emit dataSet(&qv);

But now I'm stuck on how to actually use it. I have absolutely no clue on how to incorporate that into my own app. I did a make install but neither do I know how to activate it, nor how to ensure cross platform functionality.

So I moved over to give http://qt-apps.org/content/show.php/VirtualKeyboard?content=107388 a try, which was mentioned in earlier in this thread.

Would be great if you could explain/give a sample app on how to actually use such an extra inputcontext, for the total noobs :)

StrikeByte
30th March 2015, 08:49
There is a howto on the first page of this thread

kovis
4th May 2015, 15:10
Hi, thanks for the update.
I'm pretty new to Qt (and to C++) and I'm having trouble using your project. Running Qt-Creator 3.3.0 and Qt5.4.
I can open your project, but compiling it yields errors.

This was running qmake && make in the project dir.
What am I doing wrong? Do you need any more information?

EDIT: running on OSX 10.10.2

Looks like signatures changed here and there in Qt 5.4,
your problem can get around easily as
QString editedText = ui->edValue->text();
if (validator->validate(editedText, pos) == QValidator::Acceptable)

I also changes dataSet(QVariant*) to plain value call dataSet(QVariant)

but my problem is that I never got the virtual keyboard working on Linux/X11/Qt 5.4.1

I compiled the library, did sudo make install so it got copied into the right plugin directory
I set the proper spellword "keyboard" property, hell, I even removed all property checks in the plugin to be sure this is not the problem.

But on my test application the virtual keyboard never appeared.
Actually I wonder how "magically" it could appear - currently I am missing some plugin activation on QLineEdit.

I attach my test project if anyone could see what is the reason of virtual keyboard not showing up...
Many thanks in advance

Jan Struhar

Robb
16th June 2015, 14:28
Hi @ all.

I've tried to use the keyboard in Qt 4. I included the InputDevice.h in my main file and created an intance of the InputDevice like you've posted it.
But every time I want to build by project it says "undefined reference to 'InputDevice::InputDevice()'".

Have I need to link something else or include on another place?

Thanks in advance.

natile
15th July 2015, 08:26
Hi all
I hava the same problem
I cant compile my test app, it is fail in <include "inputdevice.h">
Does anyone actually succeeded to run it ??

mvly
27th July 2015, 10:05
I am using this in on an embedded arm and the compiler is telling me they cannot find <QtDesigner/QDesignerExportWidget>.

Any way either not to use this or where I can find this file?

Thanks

StrikeByte
29th October 2015, 10:41
kovis did you try to add the plugin to your application build directory?
what to do:
* create a folder named platforminputcontexts in next to your executable
* place the plugin in this directory
* start the application

Also important is that the plugin is build in the sameway as your application (debug/release)

kiran prabhu
25th November 2015, 08:05
hi,thanks for the virtual keyboard

clutch12
24th March 2016, 01:07
This looks very useful. I've been trying out the latest VIInputContext class. Any chance you can add some clarification on usage with a mainwindow widget?
I put this in my mainwindow.h
VIInputContext inputdevice;
and in the constructor I do this
ui->lineEdit->setProperty("keyboard",true);


But, I must be missing something as when I click in the lineEdit box nothing happens.

evandropadrao
27th April 2016, 02:46
OK create one keyboard and create an instance of it in your class and use it. Or simple is that create one lineedit with keyboard having pushbuttons. and connect all the push button to your lineEdit. If you want to use your keyboard in differents gui then you have to create a different class for keyboard. if you want some help in keyboard tutorial then you're welcome to query.

I have a doubt in "If you want to use your keyboard in differents gui then you have to create a different class for keyboard": for each GUI I need create another "InputDevice" or create another "keyboard"? In this case, do I need to create another "installEventFilter". I create a tested app that in mainwindow I have some qlineedit that is working fine and a button to open a new QDialog. In this dialog, I have also some qlineedit. When I select this object, the keyboard is showed but no key pressed is accepted (I believe that slot-signal is defined to mainwindow). Could you help me ?

titan83
30th April 2016, 10:28
Hello, StrikeByte.
Great thanks for you project. I used many time your keyboard for my Qt4 application. It worked nice.
But now I want to migrate my app to Qt5 and, of course, I planned to use your virtual keyboard adopted to Qt5.
But, sorry, I had epic fail((
My environment: embedded device, Qt5.4.2, X11.
I don't understand how to load plugin to app.
I used QT_DEBUG_PLUGINS=1 and I saw that plugin was found, but it's not loaded.

QFactoryLoader::QFactoryLoader() looking at "/usr/local/qt/qt542-ti-qml/plugins/platforminputcontexts/libVirtualInput.so"
Found metadata in lib /usr/local/qt/qt542-ti-qml/plugins/platforminputcontexts/libVirtualInput.so, metadata=
{
"IID": "org.qt-project.Qt.QPlatformInputContextFactoryInterface",
"MetaData": {
"Keys": [
"virtualinput"
]
},
"className": "VIPlatformInputContextPlugin",
"debug": false,
"version": 328706
}


Got keys from plugin meta data ("virtualinput")

I tried to add DEFINES += VIRTUALINPUT_LIBRARY to .pro file.
I tried to add VIPlatformInputContextPlugin virtualKeyboard; or VIInputContext virtualKeyboard; to my main.cpp.

I saw that similar questions were above. Please give us simple project for Qt5 with your keyboard.

Thanks.

titan83
30th April 2016, 14:58
Ok. I answer to my question myself.

First: I don't know how to change input context plugins order. So I delete all other pluging from my plugins/platforminputcontexts folder. Virtual keybord plugin starts to load.
Second: I should to work under X11, not with EGLFS or LinuxFB, unfortunately( And when I pressed on QLineEdit I see nothing. But from debug output I saw that show() method is called, hide() is too. So I add | Qt::X11BypassWindowManagerHint to numpad and keyboard constructors. Also I add call raise() method after show() in both files.
Now virtual keyboard is working.

Hope it will useful.

HenrikSkott
15th February 2017, 18:30
Hi StrikeByte,

I really appreciate the work you've done with the virtual keyboard, but I notice you haven't added a license to the code. I hope this can be placed in the public doman (so anyone can use it for anything, even relicensing) or LGPL, so it can be used in projects using a LGPL licensed Qt.

Thanks,

Henrik

StrikeByte
18th January 2018, 15:08
Hey HenrikSkott,

You can do with it whatever you want.

I havn't used this keyboard for a while, but it seems Qt has changed something in the platforminputcontext loader

if you want to use it you need to add this to your main
qputenv("QT_IM_MODULE", QByteArray("virtualinput"));

JasonMa
4th June 2019, 06:40
I just created a project on github based on StrikeByte's code. https://github.com/mazj/VirtualInput