由于项目需要用到QT软键盘,本来PC上QT用的5.4.1版本,但不支持QInputContext。所以用了和开发板一样的4.8.5.
1.简单的数字软件盘
在QtEmbedded-4.8.5-arm/examples/tools/inputpanel下面有例子,下面说一下修改;
1).增加退格键,因为键值问题,需要使用quint32,才能生效,把下面的改一下就好;
myinputpanel.cpp
form.panelButton_backspace->setProperty("buttonValue", QVariant(quint32(Qt::Key_Backspace))); //设置退格键
void MyInputPanel::buttonClicked(QWidget *w)
{
quint32 chr = qvariant_cast<quint32>(w->property("buttonValue"));
emit characterGenerated(chr);
}
myinputpanelcontext.cpp
connect(inputPanel, SIGNAL(characterGenerated(quint32)), this,SLOT(sendCharacter(quint32)));
void MyInputPanelContext::sendCharacter(quint32 character)
{
QPointer<QWidget> w = focusWidget();
if (!w)
return;
QKeyEvent keyPress(QEvent::KeyPress,(quint32) character, Qt::NoModifier, QString(character));
QApplication::sendEvent(w, &keyPress);
if (!w)
return;
QKeyEvent keyRelease(QEvent::KeyRelease,(quint32)character, Qt::NoModifier, QString()); //character.unicode()
QApplication::sendEvent(w, &keyRelease);
}
注意把第二次KeyPress,改为KeyRelease,否则退格键会触发2次
2).鼠标单击弹出软件盘
在myinputpanelcontext.h中增加
class MyProxyStyle : public