Unsolved Using mousePressEvent in PyQt5
-
Hi,
I‘m trying to a use virtual keyboard for my gui in PyQt5. I already found one (https://github.com/yurisnm/pyqt5/tree/master/keyboard_full). My goal is to implement my Gui.py, build with QtCreator. I already imported the file and changed the MainWindow class for the new gui.
First the working example from GitHub, that calls the Keyboard if you click into TextEdit:
class MainWindow(QWidget): def __init__(self): super(MainWindow, self).__init__() self.layout = QVBoxLayout() self.setLayout(self.layout) self.text_edit = TextEdit(self) self.layout.addWidget(self.text_edit) self.kb = WKeyboard() self.kb.set_receiver(self.text_edit) def closeEvent(self, QCloseEvent): self.kb.close() super(MainWindow, self).closeEvent(QCloseEvent) class TextEdit(QTextEdit): def __init__(self, parent): super(TextEdit, self).__init__() self.parent = parent def mousePressEvent(self, QMouseEvent): self.parent.kb.show() super(TextEdit, self).mousePressEvent(QMouseEvent)
And here's how I edited it so far:
class MainWindow(QMainWindow, gui.Ui_Gui): def __init__(self): super(MainWindow, self).__init__() self.setupUi(self) self.edit = Text(self) self.kb = Tastatur() self.kb.set_receiver(self.edit) def closeEvent(self, QCloseEvent): self.kb.close() super(MainWindow, self).closeEvent(QCloseEvent) class Text(QLineEdit): def __init__(self, parent): super(Text, self).__init__() self.parent = parent def mousePressEvent(self, QMouseEvent): self.parent.kb.show() super(Text, self).mousePressEvent(QMouseEvent)
I named the LineEdit in QtCreator "edit".
I included Gui.py and replaced self.text_edit by self.edit.
The gui shows up, but if I click on the LineEdit nothing happens.
Are there further changes to make?
Thanks!