Windows 7 tablet--how to get virtual keyboard for text entry?
I'm just now deploying my Qt application on a Windows 7 tablet. I expected the virtual keyboard to come up whenever I touched something like an entry box, but nothing happens.
Is there something easy I can do to get the virtual keyboard (or numeric keypad) to come up, or do I need to do my own widgets for this that are only used for specific platforms (that don't have physical keyboards).
Thanks,
Dave Thomas
Re: Windows 7 tablet--how to get virtual keyboard for text entry?
You need a working input context plugin. I don't know if Qt provides one for Win7 tablets. If not, either search the net or implement your own.
Re: Windows 7 tablet--how to get virtual keyboard for text entry?
No clue what a "working input context plugin" is, but I like learning new things. If it's a big deal, I can just do my own widget that comes up when the entry boxes (or equivalent) are clicked.
Thanks!
Dave Thomas
Re: Windows 7 tablet--how to get virtual keyboard for text entry?
Re: Windows 7 tablet--how to get virtual keyboard for text entry?
I used this example:
http://qt-project.org/doc/qt-4.8/tools-inputpanel.html
Thanks!
Dave Thomas
Added after 56 minutes:
That works (http://qt-project.org/doc/qt-4.8/tools-inputpanel.html) except I can only add digits, not replace or delete them.
So, I'm trying to add a "clear" or "delete" button. I replaced the "*" button in Qt Designer with one labelled "Clear" and added a dynamic "buttonValue" with value "C". So a signal gets emitted from "MyInputPanel" with a parameter of 'C' when that button is touched
The slot in MyInputPanelContext receives the signal with the QChar 'C'. KeyPress and KeyRelease events are generated for the other buttons and sent using QApplicaiton::sendEvent. I'm not aware of an event that will always map to something that will clear the contents of a spinbox, for example.
So, I'm thinking I'd add a dynamic cast of the widget in focus to each of the widget types for which my application will need the clear function. The call the clear() method after the first dynamic cast that succeeds.
I'm thinking this might not be the "smart way" to do it but I think it will work. Is there a better way?
Thanks,
I used this example:
http://qt-project.org/doc/qt-4.8/tools-inputpanel.html
Thanks!
Dave Thomas
Added after 56 minutes:
That works (http://qt-project.org/doc/qt-4.8/tools-inputpanel.html) except I can only add digits, not replace or delete them.
So, I'm trying to add a "clear" or "delete" button. I replaced the "*" button in Qt Designer with one labelled "Clear" and added a dynamic "buttonValue" with value "C". So a signal gets emitted from "MyInputPanel" with a parameter of 'C' when that button is touched
The slot in MyInputPanelContext receives the signal with the QChar 'C'. KeyPress and KeyRelease events are generated for the other buttons and sent using QApplicaiton::sendEvent. I'm not aware of an event that will always map to something that will clear the contents of a spinbox, for example.
So, I'm thinking I'd add a dynamic cast of the widget in focus to each of the widget types for which my application will need the clear function. The call the clear() method after the first dynamic cast that succeeds.
I'm thinking this might not be the "smart way" to do it but I think it will work. Is there a better way?
Thanks,
I used this example:
http://qt-project.org/doc/qt-4.8/tools-inputpanel.html
Thanks!
Dave Thomas
Added after 56 minutes:
That works (http://qt-project.org/doc/qt-4.8/tools-inputpanel.html) except I can only add digits, not replace or delete them.
So, I'm trying to add a "clear" or "delete" button. I replaced the "*" button in Qt Designer with one labelled "Clear" and added a dynamic "buttonValue" with value "C". So a signal gets emitted from "MyInputPanel" with a parameter of 'C' when that button is touched
The slot in MyInputPanelContext receives the signal with the QChar 'C'. KeyPress and KeyRelease events are generated for the other buttons and sent using QApplicaiton::sendEvent. I'm not aware of an event that will always map to something that will clear the contents of a spinbox, for example.
So, I'm thinking I'd add a dynamic cast of the widget in focus to each of the widget types for which my application will need the clear function. The call the clear() method after the first dynamic cast that succeeds.
I'm thinking this might not be the "smart way" to do it but I think it will work. Is there a better way?
Thanks,
Added after 49 minutes:
Not elegant, but this works:
Code:
void MyInputPanelContext
::sendCharacter(QChar character
) {
QPointer<QWidget> w = focusWidget();
if (!w)
return;
if (character == 'C')
{
return;
}
if (!w)
return;
}
Re: Windows 7 tablet--how to get virtual keyboard for text entry?
Basing your solutions on tutorials or examples that have simple usecases in mind often yields bad results -- like in this case.
Why are you trying to "extend" sendCharacter() when in your case it is not true that every keypress yields a new QChar element that should be added to the input? A trivial solution is to connect the "delete" key to a separate slot (or whatever else piece of code you have) that will generate a proper event and send it to the focus widget.
Code:
connect(myDeleteButton, SIGNAL(clicked()), myContext, SLOT(sendDelete()));
// ...
void MyInputPanelContext::sendDelete() {
if(!focusWidget()) return;
}
Re: Windows 7 tablet--how to get virtual keyboard for text entry?
Yes, I like that better.
Thanks!
Dave Thomas
Added after 52 minutes:
Except it doesn't work. focusWidget() is returning zero in the sendDelete() method. Yet, it correctly returns a pointer to the spinBox widget when any other button is pushed in the sample code's "sendchCharacter" . I do have the focusPolicy for the delete button set to "NoFocus".
That doesn't make sense. From the Qt docs:
QWidget * QApplication::focusWidget () [static]
Returns the application widget that has the keyboard input focus, or 0 if no widget in this application has the focus.
Why would the keyboard focus be changing?
Re: Windows 7 tablet--how to get virtual keyboard for text entry?
Maybe you forgot to set your button's focus policy in the input panel to NoFocus and it steals focus from whatever had focus before or something like that.
Re: Windows 7 tablet--how to get virtual keyboard for text entry?
No, I did have the focusPolicy to NoFocus for the new button.
I had the send_delete a member function of MyInputPanel when the focusWidget() call was returning null. When I instead made it a member function of MyInputPanelContext (which required making the keypad ui form a public member of MyInput so I could do the connection int the MyInputPanelContext constructor), it works fine.
Don't understand that at all--but not sure I care now that it's working.