参考文章:Qt5 QLineEdit实现点击调用软键盘
#include <Windows.h>
#pragma comment(lib, "user32.lib")
ui->lineEdit1->installEventFilter(this);
ui->lineEdit2->installEventFilter(this);
bool ClassName::eventFilter(QObject *watched, QEvent *event)
{
if ( (watched == ui->lineEdit1||watched == ui->lineEdit2) && (event->type() == QEvent::MouseButtonPress) )
{
callKeyBoard();
}
return QWidget::eventFilter(watched,event);
}
void ClassName::callKeyBoard()
{ PVOID OldValue;
BOOL bRet = Wow64DisableWow64FsRedirection (&OldValue);
QString csProcess="C:\\Windows\\System32\\osk.exe";
QString params="";
ShellExecute(NULL, L"open", (LPCWSTR)csProcess.utf16(), (LPCWSTR)params.utf16(), NULL, SW_SHOWNORMAL);
if ( bRet )
{
Wow64RevertWow64FsRedirection(OldValue);
}
}