Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 462595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:05:25+00:00 2026-05-12T23:05:25+00:00

I am having problem filtering the mousePressEvent with installEventFilter MyTestxEdit is a widget that

  • 0

I am having problem filtering the "mousePressEvent" with installEventFilter

MyTestxEdit is a widget that holds QTextEdit
I want that all the events of QTextEdit will be handle by MyTestxEdit
I have used the installEventFilter
This Trick works well for events like keyPressEvent but doesn’t handle the mousePressEvent
what am i doing wrong?

import sys
from PyQt4.QtGui import QApplication, QErrorMessage
from KdeQt.KQApplication import KQApplication
from KdeQt.KQMainWindow import KQMainWindow
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import thread

class MyTestxEdit1(QTextEdit):
    def __init__(self,parent):
        QTextEdit.__init__(self)
        self.setMouseTracking(True)

class MyTestxEdit(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.__qTextEdit=MyTestxEdit1(self)
        self.__qHBoxLayout=QHBoxLayout()
        self.setLayout(self.__qHBoxLayout)
        self.__qHBoxLayout.addWidget(self.__qTextEdit)        
        self.__qTextEdit.installEventFilter(self)


    def eventFilter(self,target,event):
        print "eventFilter "+str(event.type())
        if(event.type()==QEvent.MouseButtonPress):
            print "Mouse was presssed "+str(event.type())
            self.mousePressEvent(event) 
            return True
        return False                   


if __name__ == '__main__':
    app = KQApplication(sys.argv,[])
    mainWindow = KQMainWindow()#loc, splash, pluginFile, noopen, restartArgs)
    s = QSize(800, 600)
    mainWindow.resize(s)    
    testxEdit=MyTestxEdit()
    mainWindow.setCentralWidget(testxEdit)

    mainWindow.show()
    res = app.exec_()
    sys.exit(res)    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:05:25+00:00Added an answer on May 12, 2026 at 11:05 pm

    Try to install the filter on the QTextEdit's viewport instead of the QTextEdit itself…

    I don’t know python but something like:

    self.__qTextEdit.viewport().installEventFilter(self)
    

    I hope it helps!

    You should do something like:

    MyClassFrm::MyClassFrm()
    {
        ...
        // Get your TextEdit from the UI here , or create your TextEdit here....
        // Install the filter
        pMyTextEdit->viewport()->installEventFilter(this);
        ...
    }
    
    ...
    
    bool MyClassFrm::eventFilter(QObject* pObject, QEvent* pEvent)
    {
        if (pEvent->type() == QEvent::MousePressEvent) 
        {
            qDebug() << "Mouse pressed !!";
            // standard event processing
            return QObject::eventFilter(pObject, pEvent);
        }
    }
    

    You should be able to make it work, I just tested in a my application, it works… I’m sure you’re close!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.