Я также не могу понять, как загрузить style.qml, но я экспериментировал с некоторыми вещами и смог придумать следующее:
Это сделает фон клавиатуры прозрачным, если поместить его внутрь.InputPanel
:
Component.onCompleted: {
keyboard.style.keyboardBackground = null; // the keyboard background
keyboard.style.selectionListBackground = null; // the horizontal bar at the
// top of the keyboard
}
Затем вы можете изменить цвет фона, определив родного брата следующим образом:
Rect {
anchors.fill: inputPanel
color: "red"
}
InputPanel.keyboard.style
имеет множество свойств, с которыми вы можете поэкспериментировать.В Qt-Creator нет автоматического завершения для них, но вы можете распечатать их на консоли следующим образом:
console.log(Object.keys(inputPanel.keyboard.style).sort());
Надеюсь, это поможет.
Полный код, протестирован на Qt 5.12 LinuxGCC:
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.5
import QtQuick.VirtualKeyboard 2.2
Window {
id: window
visible: true
width: 640
height: 480
title: qsTr("Hello World")
// window background
Rectangle {
anchors.fill: parent
gradient: Gradient {
GradientStop { position: 0.0; color: "yellow" }
GradientStop { position: 1.0; color: "green" }
}
}
// keyboard background
Rectangle {
anchors.fill: inputPanel
color: 'red'
visible: !checkBox.checked
}
Column {
TextField {
color: "white"
background: Rectangle { color: "black" }
focus: true
}
CheckBox {
id: checkBox
text: 'Invisible Keyboard Background'
}
}
InputPanel {
id: inputPanel
z: 99
x: 0
y: window.height
width: window.width
Component.onCompleted: {
keyboard.style.keyboardBackground = null;
keyboard.style.selectionListBackground = null;
}
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
}
}
}
}
}