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. Add mouse event to QTextEdit
Forum Updated to NodeBB v4.3 + New Features

Add mouse event to QTextEdit

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 388 Views 1 Watching
  • 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.
  • N Offline
    N Offline
    Nightmaster
    wrote on last edited by
    #1

    Hi All

    I have the following code where I am testing when a mouse is clicked inside a QTextEdit.

    This code worked when I used QPushButton but in the application where this will be used it will be a QTextEdit.
    The second print statement " I have been clicked" never gets executed, what am i doing wrong please?

    class firstScreen(QWidget): 
        def __init__(self):
            super().__init__() 
    
            
            self.resize(500,500)
            self.setWindowTitle("Mouse button event test")
    
    
            self.text_edit = QtWidgets.QTextEdit(self)  
            self.text_edit.setGeometry(QtCore.QRect(200, 200, 150, 80))  
            self.text_editsetText("Click me")  
            self.text_editinstallEventFilter(self)
    
    
    
    
    
        def eventFilter(self, QObject , QEvent ):
    
    
                if QObject == self.register:
                    print("enter")
    
                    if QEvent.type() == QEvent.MouseButtonPress:
                        mousey_event = QtGui.QMouseEvent(QEvent)
                        
    
                        #
                        print("i have been clicked" , mousey_event.button())
    
                    else:
                        
                return super(firstScreen, self).eventFilter(QObject, QEvent)
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please provide a full runnable testing script. This one contains invalid code.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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