forked from AKOBIBILI/pyqt_virtual_keyboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
39 lines (28 loc) · 1 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sys
from PyQt5.QtWidgets import QApplication, QLineEdit, QMainWindow, QVBoxLayout, QWidget
from pyqt_virtual_keyboard import KeyboardDialog
class MainWindow(QMainWindow):
def __init__(self) -> None:
super().__init__()
self._init_ui()
def _init_ui(self) -> None:
self.focused_input = None
self.line_edit: QLineEdit = QLineEdit()
self.line_edit.mousePressEvent = self.handle_mouse_press
layout = QVBoxLayout()
layout.addWidget(self.line_edit)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
def handle_mouse_press(self, e):
self.focused_input = self.line_edit
keyboard = KeyboardDialog(self)
keyboard.exec_(self.line_edit.text())
def on_key(self, keys):
if self.focused_input is not None:
self.focused_input.setText(keys)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()