#include "myinputpanelcontext.h" #include "myinputpanel.h" #include MyInputPanelContext::MyInputPanelContext() { inputPanel = new MyInputPanel; connect(inputPanel, SIGNAL(characterGenerated(QChar)), SLOT(sendCharacter(QChar))); } //! [0] MyInputPanelContext::~MyInputPanelContext() { delete inputPanel; } //! [1] bool MyInputPanelContext::filterEvent(const QEvent* event) { //点击输入栏时发生,软件盘弹出事件 if (event->type() == QEvent::RequestSoftwareInputPanel) { // updatePosition();//更新位置 inputPanel->move(450,200); inputPanel->show();//显示 inputPanel->clearLineEditData(); return true; } else if (event->type() == QEvent::CloseSoftwareInputPanel) { inputPanel->hide(); return true; } return false; } //! [1] QString MyInputPanelContext::identifierName() { return "MyInputPanelContext"; } void MyInputPanelContext::reset() { } bool MyInputPanelContext::isComposing() const { return false; } QString MyInputPanelContext::language() { return "en_US"; } //! [2] void MyInputPanelContext::sendCharacter(QChar character) { // QPointer w = focusWidget(); //获取输入窗口指针 QPointer w = inputPanel->getFocusedWidget(); if (!w) return; qDebug() << "send"<rect();//返回窗口部件的矩形对象 //QPoint panelPos = QPoint(widgetRect.left()+10, widgetRect.bottom() + 12);//以输入光标点处的x,y坐标,来确定输入面板的放置位置信息 QPoint panelPos = QPoint(focus.x() + 16, focus.y() +20);//以输入光标点处的x,y坐标,来确定输入面板的放置位置信息 // qDebug() << panelPos <mapToGlobal(panelPos); qDebug() << panelPos <move(panelPos);//移到设置点处 }