<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to redirect Wheel events of QWidget to QTextEdit   ?]]></title><description><![CDATA[<p dir="auto">when you turn the mouse wheel while the mouse cursor is not on the QTextEdit ,the scroll bars will not move in such case ,but I still want to move the scroll bars by mouse wheel ,so how can I implement this function ?<br />
I know some software like Microsoft Word have this feature .</p>
<p dir="auto">I implement this feature like the following ,but when you move the scroll bars to the top or bottom by mouse wheel ,an error would occur : maximum recursion depth exceeded while calling a Python object.<br />
anyone can help ?<br />
@<br />
import sys<br />
from PyQt4.QtGui import *<br />
from PyQt4.QtCore import *<br />
class BoxLayout(QWidget):<br />
def <strong>init</strong>(self, parent=None):<br />
super(BoxLayout, self).<strong>init</strong>(parent)<br />
self.resize(100, 300)</p>
<pre><code>    ok = QPushButton("OK")
    cancel = QPushButton("Cancel")
    self.textEdit = QTextEdit("""This function returns true if the contents of the MIME data object, specified by source , can be decoded and inserted into the document. It is called for example when during a drag operation the mouse enters this widget and it is necessary to determine whether it is possible to accept the drag and drop operation.""")
    
    vbox = QVBoxLayout()
    vbox.addWidget(self.textEdit)
    vbox.addWidget(ok)
    vbox.addWidget(cancel)
    self.setLayout(vbox)
</code></pre>
<h1>self.textEdit.installEventFilter(self)</h1>
<h1></h1>
<h1>def eventFilter(self, obj, event):</h1>
<h1>if obj == self.textEdit:</h1>
<h1>if event.type() == QEvent.Wheel:</h1>
<h1>self.textEdit.wheelEvent(event)</h1>
<h1>return True</h1>
<h1>else:</h1>
<h1>return False</h1>
<h1>else:</h1>
<h1>return QMainWindow.eventFilter(self, obj, event)</h1>
<h1></h1>
<pre><code>def wheelEvent(self, event):
    self.textEdit.wheelEvent(event)
</code></pre>
<p dir="auto">app = QApplication(sys.argv)<br />
qb = BoxLayout()<br />
qb.show()<br />
sys.exit(app.exec_())<br />
@</p>
]]></description><link>https://forum.qt.io/topic/29613/how-to-redirect-wheel-events-of-qwidget-to-qtextedit</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 09:02:11 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/29613.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 19 Jul 2013 06:00:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to redirect Wheel events of QWidget to QTextEdit   ? on Fri, 19 Jul 2013 06:45:27 GMT]]></title><description><![CDATA[<p dir="auto">Hmm, You might need to redirect the mouseEvent for the "parent" qidget or even for the MainWindow where all widgets are placed. Or maybe check out eventFilters. The widget that has "focus" will get the event, so you need to redirect it.</p>
]]></description><link>https://forum.qt.io/post/187068</link><guid isPermaLink="true">https://forum.qt.io/post/187068</guid><dc:creator><![CDATA[Jeroentjehome]]></dc:creator><pubDate>Fri, 19 Jul 2013 06:45:27 GMT</pubDate></item></channel></rss>