键盘样式一:
键盘样式二:
Qt官方软键盘示例:
要想使用Qt中的虚拟键盘,需要以下几个步骤:
1.修改你的.pro文件,添加如下内容:
static {
QT += svg
QTPLUGIN += qtvirtualkeyboardplugin
}
QT_VIRTUALKEYBOARD_STYLE=qtvirtualkeyboard myapp
2.在main.cpp中添加以下代码:
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
3.在QML文件中添加以下内容:
import QtQuick.VirtualKeyboard 2.13
InputPanel {
id: inputPanel
z: 99
x: (window.width-inputPanel.width)*0.5
y: window.height
width:getwidth(window.width,window.height,dp(1100))
states: State {
name: "visible"
when: inputPanel.active
PropertyChanges {
target: inputPanel
y: window.height - inputPanel.height
}
}
transitions: Transition {
from: ""
to: "visible"
reversible: true
//设置键盘弹出效果
ParallelAnimation {
NumberAnimation {
properties: "y"
//过渡时间
duration: 100
//弹出效果
easing.type: Easing.InOutQuad
}
}
}
}
经过以上三个步骤,就可以掉出QML的虚拟键盘。
如果要想修改键盘样式则修改main.cpp,添加以下内容:
qputenv("QT_VIRTUALKEYBOARD_STYLE", QByteArray("retro"));