ZioByte
ZioByte

Reputation: 3034

QtVirtualKeyboard/PyQt6 - how to link OSK to specific input widget?

I have several questions concerning QtVirtualKeyboard usage under PyQt6 so, since StackOverflow policy is "just one question" I will post several questions.

First part will be the same because they all pertain to same setup.

Common Setup

I installed QtVirtualKeyboard loosely following this answer (MANY Thanks @eyllanesc!).

Exact commands given are:

python3 -m venv venv
venv/bin/pip install -U pip wheel PyQt6 aqtinstall
QT_PREFIX_PATH=$(venv/bin/python -c "from PyQt6.QtCore import QLibraryInfo; print(QLibraryInfo.path(QLibraryInfo.LibraryPath.PrefixPath), end=None)")
QT_VERSION_STR=$(venv/bin/python -c "from PyQt6.QtCore import QT_VERSION_STR; print(QT_VERSION_STR, end=None)")
QT_VERSION_STR=6.7.3
venv/bin/python -m aqt install-qt linux desktop $QT_VERSION_STR -m qtvirtualkeyboard --outputdir qt
cp -p qt/$QT_VERSION_STR/gcc_64/lib/libQt6VirtualKeyboard.so.$QT_VERSION_STR $QT_PREFIX_PATH/lib/libQt6VirtualKeyboard.so.6
cp -p qt/$QT_VERSION_STR/gcc_64/lib/libQt6VirtualKeyboardSettings.so.$QT_VERSION_STR $QT_PREFIX_PATH/lib/libQt6VirtualKeyboardSettings.so.6
mkdir -p $QT_PREFIX_PATH/plugins/platforminputcontexts
cp -p qt/$QT_VERSION_STR/gcc_64/plugins/platforminputcontexts/libqtvirtualkeyboardplugin.so $QT_PREFIX_PATH/plugins/platforminputcontexts
#cp -pr qt/$QT_VERSION_STR/gcc_64/plugins/virtualkeyboard $QT_PREFIX_PATH/plugins
cp -pr qt/$QT_VERSION_STR/gcc_64/qml/QtQuick/VirtualKeyboard $QT_PREFIX_PATH/qml/QtQuick
mkdir -p $QT_PREFIX_PATH/qml/Qt/labs
cp -pr qt/$QT_VERSION_STR/gcc_64/qml/Qt/labs/folderlistmodel $QT_PREFIX_PATH/qml/Qt/labs

Note: I had to force QT_VERSION_STR=6.7.3 because using the value given by Python script above (6.7.1) I had a runtime error (something 6.7.3 not found); can that be hinting something is wrong in my setup?

Test program is:

from PyQt6.QtWidgets import QApplication, QWidget, QMainWindow, QLineEdit, QVBoxLayout

import sys
import os
os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard"

class MaiWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.line_edit = QLineEdit()
        self.line_edit2 = QLineEdit()
        self.layout = QVBoxLayout()
        self.main_widget = QWidget()
        self.main_widget.setLayout(self.layout)
        self.layout.addWidget(self.line_edit)
        self.layout.addWidget(self.line_edit2)
        self.setCentralWidget(self.main_widget)


app = QApplication(sys.argv)

window = MaiWindow()
window.show()

app.exec()

Program is started using: venv.hide/bin/python test.py.

This correctly shows a virtual keyboard when focusing into either QLineEdit.

Question 2

How should I modify the test code (if it is possible at all) in order to have the first QLineEdit to use "normal" system keyboard and the second one the on-screen QtVirtualKeyboard?

Reason for this request is the Virtual Keyboard should be in another Locale (details in next question).

Upvotes: 1

Views: 35

Answers (0)

Related Questions