6

Qt5.14.2使用虚拟键盘 - Lee'sEngineer

 2 years ago
source link: https://www.cnblogs.com/lees-engineer/p/16667341.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Qt5.14.2使用虚拟键盘

这是关于Qt5(Qt5.1.4.2),QWidget编程使用Qt虚拟键盘(qtvirtualkeyboard)
Tag: QT5,Qt,软件盘、虚拟键盘,Widget程序,QML
启用虚拟键盘模块
在QApplication对象创建之前插入代码:
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

 有这句话之后,QtCreator中运行程序即可有如下效果:(但存在键盘挡住输入框的问题,后面会解决)。

0
处理视图推拉
对于Qwidget程序,使用qtvirtualkeyboard弹出键盘之后,键盘会浮于表面。
使用VirtualkeyboardPushView模块,自动根据情况把输入视图往上面推移,关键代码如下:
#include "mainwindow.h"
#include <QApplication>
#include "VirtualkeyboardPushView.h"
int main(int argc, char *argv[])
{
/// 第一步
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QApplication a(argc, argv);
/// 第二步
VirtualkeyboardPushView keyboardHelper;
keyboardHelper.makeCompilerHappy();
MainWindow w;
w.show();
return a.exec();
}

  运行效果如下(对于新窗口也只会推动新的窗口):

987469-20220907212058245-82042731.gif
为了让程序独立运行,拷贝QT的库到运行目录,需要的库如下(Qt5.14.2 + vs2017 x86):
0

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK