问题
It is possible to show Virtual Keyboard in QQuickWidget or in QWidget?
I have QWidget application and I need to have better control where VirtualKeyboard is shown.
Today I spend all my day to find a solution, unfortunately without success.
回答1:
The following code shows that it is valid to use virtualkeyboard in QQuickWidget.
main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickWidget>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QQuickWidget widget;
widget.setResizeMode(QQuickWidget::SizeRootObjectToView);
widget.setSource(QStringLiteral("qrc:/main.qml"));
widget.show();
return app.exec();
}
main.qml
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.VirtualKeyboard 2.14
Rectangle {
id: window
width: 640
height: 480
TextEdit{
text: "Hello world"
anchors.centerIn: parent
}
InputPanel {
id: inputPanel
z: 99
x: 0
y: window.height
width: window.width
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: 250
easing.type: Easing.InOutQuad
}
}
}
}
}
qml.qrc
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>
59777221.pro
QT += quickwidgets virtualkeyboard
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
RESOURCES += qml.qrc
├── 59777221.pro
├── main.cpp
├── main.qml
└── qml.qrc
来源:https://stackoverflow.com/questions/59777221/qt-virtual-keyboard-in-qquickwidget