Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Using mousePressEvent in PyQt5
Qt 6.11 is out! See what's new in the release blog

Using mousePressEvent in PyQt5

Scheduled Pinned Locked Moved Unsolved Qt for Python
1 Posts 2 Posters 8.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matze_121
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved