'QVirtualKeyboard default style for PySide6 and PySide2 not the same
Solution 1:[1]
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/qt5defaultThe 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.qrcChange 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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


