I use the keyboard in the project written on pyside2, without any additional settings it looks like this:
But the same code on pyside6 displays the keyboard in another style:
How can I use style from pyside2 in pyside6?
One possible solution is to download the qtvirtualkeyboard style from Qt5 and use it in Qt6:
Copy the default style from the Qt5 branch of qtvirtualkeyboard to the qml/QtQuick/VirtualKeyboard/Styles/
folder next to the .py file with another name.
mkdir -p qml/QtQuick/VirtualKeyboard/Styles/
git clone -b 5.15.2 https://code.qt.io/qt/qtvirtualkeyboard.git
cp -rf qtvirtualkeyboard/src/virtualkeyboard/content/styles/default qml/QtQuick/VirtualKeyboard/Styles/qt5default
The structure should be the following:
├── main.py
└── qml
└── QtQuick
└── VirtualKeyboard
└── Styles
└── qt5default
├── images
│ ├── backspace-868482.svg
│ ├── check-868482.svg
│ ├── enter-868482.svg
│ ├── globe-868482.svg
│ ├── handwriting-868482.svg
│ ├── hidekeyboard-868482.svg
│ ├── search-868482.svg
│ ├── selectionhandle-bottom.svg
│ ├── shift-80c342.svg
│ ├── shift-868482.svg
│ ├── shift-c5d6b6.svg
│ └── textmode-868482.svg
├── style.qml
└── virtualkeyboard_default_style.qrc
Change line:
readonly property string resourcePrefix: "qrc:/QtQuick/VirtualKeyboard/content/styles/default/"
to:
readonly property string resourcePrefix: ""
In the .py you must include the qml to QML_IMPORT_PATH and set QT_VIRTUALKEYBOARD_STYLE with the new style:
import os
from pathlib import Path
import sys
from PySide6.QtWidgets import QApplication, QLineEdit
CURRENT_DIRECTORY = Path(__file__).resolve().parent
def main():
os.environ["QML_IMPORT_PATH"] = os.fspath(CURRENT_DIRECTORY / "qml")
os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"
os.environ["QT_VIRTUALKEYBOARD_STYLE"] = "qt5default"
app = QApplication(sys.argv)
w = QLineEdit()
w.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()