[英]How launch Qt Virtual keyboard only for Tablet Mode in Windows
I am making an application for Windows desktops and tablets.我正在为 Windows 台式机和平板电脑制作应用程序。 I need to launch Qt virtual keyboard in tablet mode.
我需要在平板电脑模式下启动 Qt 虚拟键盘。
I followed this example in Qt docs我在 Qt 文档中遵循了这个例子
I just put one line of code in my main.cpp to get Qt virtual keyboard working我只是在我的 main.cpp 中放了一行代码来让 Qt 虚拟键盘工作
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
But now virtual keyboard launches in desktop mode also, which is not needed.但是现在虚拟键盘也在桌面模式下启动,这是不需要的。 How do I restrict the Qt virtual keyboard for tablet mode only?
如何限制 Qt 虚拟键盘仅用于平板电脑模式?
I am using Qt 5.9 and tried 5.12.我正在使用 Qt 5.9 并尝试了 5.12。 Windows on-screen keyboard does not launch all the time when needed
Windows 屏幕键盘在需要时不会一直启动
For checking tablet mode you can use bool QWindowsWindowFunctions::isTabletMode()
static function which is introduced in Qt 5.9.要检查平板电脑模式,您可以使用 Qt 5.9 中引入的
bool QWindowsWindowFunctions::isTabletMode()
静态函数。 For enabling virtual keyboard in table mode and disabling in desktop mode you can periodically check it in a timer and show/hide InputPanel
respectively:要在表格模式下启用虚拟键盘并在桌面模式下禁用,您可以定期在计时器中检查它并分别显示/隐藏
InputPanel
:
InputPanel {
id: inputPanel
property bool enableKeyboard: false
...
states: State {
name: "visible"
when: enableKeyboard && inputPanel.active
PropertyChanges {
target: inputPanel
y: appContainer.height - inputPanel.height
}
}
...
}
enableKeyboard
property is defined to activate/deactivate keyboard and it should be updated regularly using a Timer
like: enableKeyboard
属性被定义为激活/停用键盘,它应该使用Timer
定期更新,例如:
Timer {
onTriggered: enableKeyboard = utils.isTabletMode()
running: true
repeat: true
interval: 1000
}
You should define isTabletMode
function in a QObject
based class like:您应该在基于
QObject
的类中定义isTabletMode
函数,例如:
#include <QtPlatformHeaders/QWindowsWindowFunctions>
...
Q_INVOKABLE bool isTabletMode() {
return QWindowsWindowFunctions::isTabletMode();
}
Do not forget to expose you class to qml by:不要忘记通过以下方式将您的课程暴露给 qml:
qmlengine->rootContext()->setContextProperty("utils", pointerToMyClass);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.