-
大小: 12.52MB文件類型: .7z金幣: 1下載: 0 次發布日期: 2023-07-28
- 語言: 其他
- 標簽:
資源簡介
qt輸入法, qt有兩類輸入法 一個是基于QInputContext 高版本適用 一個是基于QWSMethod低版本嵌入式使用。 我的代碼在VS2010下編寫。 你在調試前請安裝qt的VS2010插件。與qtVS庫,就直接可以編譯運行 InputContext,QWSMehod的高版本編譯不了,請在linux上安裝低版本后編譯。 在hi3510板子上運行成功。 本人低版本是4.5.3,高版本是4.8.1.其他版本未測試,請謹慎下載。
代碼片段和文件信息
#include?
#include?“inputmethod.h“
#include?“login.h“
InputMethod::InputMethod()
{
????keyboard?=?new?KeyBoard;
connect(?keyboard?SIGNAL(?characterGenerated(QChar)?)?SLOT(setInputText(QChar?)?)?);
}
InputMethod::~InputMethod()
{
????delete?keyboard;
}
/*
*?Name?:?void?eventFilter(Qobject?*obj?QEvent?*event);
*?Type?:?QEvent
*?Func?:?judge?input?method?event
*?In???:?QobjectQEvent
*?Out??:?bool
*/
bool?InputMethod::eventFilter(Qobject?*obj?QEvent?*event)
{
????if(event->type()==QEvent::MouseButtonPress)
????{
????????emit?setImObjName(obj->objectName());?//send?the?object?Name?of?event?to?judge?who?trigger?it
????????//qDebug()?<objectName();
????????showKeyBoard();
????????return?true;
????}
????return?Qobject::eventFilter(objevent);
}
/*
*?Name?:?void?showKeyBoard();
*?Type?:?function
*?Func?:?show?keyBoard
*?In???:?Null
*?Out??:?Null
*/
void?InputMethod::showKeyBoard()
{
????keyboard->move(50120);
keyboard->show();
}
void?InputMethod::setInputText(?QChar?c?)
{
QPointer?w?=?QApplication::focusWidget();
if?(!w)
return;
/*?當收到按鍵面板的按鍵輸入后,分別向當前焦點Widget發送KeyPress和KeyRelease事件?*/
QKeyEvent?keyPress(QEvent::KeyPress?c.unicode()?Qt::NoModifier?QString(c));
QApplication::sendEvent(w?&keyPress);
if?(!w)
return;
QKeyEvent?keyRelease(QEvent::KeyRelease?c.unicode()?Qt::NoModifier?QString(c));
QApplication::sendEvent(w?&keyRelease);
}
QString?InputMethod::identifierName()
{
return?““;
}
QString?InputMethod::language()
{
return?““;
}
void?InputMethod::reset()
{
}
void?InputMethod::update()
{
}
bool?InputMethod::isComposing()?const
{
return?true;
}
bool?InputMethod::filterEvent(?const?QEvent?*event?)
{
if?(event->type()?==?QEvent::RequestSoftwareInputPanel)?
{
/*?當某個Widget請求軟鍵盤輸入時,顯示軟鍵盤?*/
keyboard->show();
return?true;
}
else?if?(event->type()?==?QEvent::CloseSoftwareInputPanel)?
{
/*?當某個Widget請求關閉軟鍵盤輸入時,關閉軟鍵盤?*/
// keyboard->hide();
return?true;
}
return?false;
}
評論
共有 條評論