02-09-2013 12:33 PM
Does anyone have any ideas on how to control when the virtual keyboard appears in a Qt application?
The keyboard seems to roll out at odd times like when a QListWidget is clicked. I would like to, for example, limit this to only when a QLineEdit is in focus.
I have looked at the event filters and posting QEvent::CloseSoftwareInputPanel but this is a kludge (and it doesnt really solve the problem). There must be a better way to do this.
02-13-2013 11:44 PM
After some experimenting and googling I found a solution to this problem.
In the source code for Qt 4.8.3 - QBBInputContext - the keyboard is rolled out whenever a widget aquires focus. By adding checks for the inputContextHint() or commenting the 'showKeyboard()' function the keyboard only appears when it is needed (from QEvent::RequestSoftwareInputPanel).
void QBBInputContext::setFocusWidget(QWidget *w)
qDebug() << Q_FUNC_INFO << (w ? "requesting" : "hiding") << "virtual keyboard";
// Original only checked if QWidget 'w' was non-zero
// if (w)
if (w != 0 && ((w->inputMethodHints() & Qt::ImhHiddenText) || (w->inputMethodHints() & Qt::ImhExclusiveInputMask)))
// Optionally comment out the 'showKeyboard()' member function.
The default input context hint for QWidgets is 'Qt::ImhNone' so this test is likely redundant; hiding the show keyboard command would do the same thing.
The only down side is that any edit box must be clicked twice (once to focus and once to open the keyboard). Since I only have one edit box I am Ok with that as it is better than having the keyboard appear when a scroll bar is moved or a button is pressed.
02-14-2013 12:08 AM
"The only down side is that any edit box must be clicked twice (once to focus and once to open the keyboard)."
I agree there, there is reference to being able to programatticaly set focus but im not sure how to go about doing that , but all it says is that it's possible i've yet to find anything pre-defined