Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 10
Registered: ‎01-15-2013
My Device: Playbook
My Carrier: Rogers

Qt - Playbook - Virtual Keyboard rollout

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.

Contributor
Posts: 10
Registered: ‎01-15-2013
My Device: Playbook
My Carrier: Rogers

Re: Qt - Playbook - Virtual Keyboard rollout

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)
{
#if defined(QBBINPUTCONTEXT_DEBUG)
    qDebug() << Q_FUNC_INFO << (w ? "requesting" : "hiding") << "virtual keyboard";
#endif
    QInputContext::setFocusWidget(w);

// Original only checked if QWidget 'w' was non-zero
//  if (w)
    if (w != 0 && ((w->inputMethodHints() & Qt::ImhHiddenText) || (w->inputMethodHints() & Qt::ImhExclusiveInputMask)))
    {
        if (qobject_cast<QAbstractSpinBox*>(w))
            mVirtualKeyboard.setKeyboardMode(QBBAbstractVirtualKeyboard::Phone);
        else
            mVirtualKeyboard.setKeyboardMode(QBBAbstractVirtualKeyboard::Default);

// Optionally comment out the 'showKeyboard()' member function.
        mVirtualKeyboard.showKeyboard();
    }
    else
    {
        mVirtualKeyboard.hideKeyboard();
    }
}

 

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.

Developer
Posts: 826
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: Qt - Playbook - Virtual Keyboard rollout

"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