[QScintilla] Mouse event filter for QsciScintilla

VA dev+pyqt at indigo.re
Mon Nov 13 20:02:36 GMT 2017


Le 13/11/2017 à 20:35, Phil Thompson a écrit :
> On 13/11/2017 18:41, VA wrote:
>> Le 13/11/2017 à 15:49, Phil Thompson a écrit :
>>> They do receive mouse press events. They are consumed (ie. accepted) 
>>> and so do not make it to the event filter.
>>
>> Why don't they pass through the event filter as other events?
> 
> That’s the way Qt works. If a mouse or key event is ignored (rather than 
> accepted) then it will be passed to the filter.

It's the opposite in Qt, the event filter is tested first, and if the 
filter returns true, the event will not even reach the widget.
See the reference doc:
https://doc.qt.io/qt-5/qobject.html#installEventFilter

And test this code where no text can be typed in a QtWidgets.QTextEdit 
(and no mouse clicks) because an event filter filters events before the 
QTextEdit receives them:

class Filter(QObject):
	def eventFilter(self, target, ev):
		return True

app = QApplication([])
f = Filter()
sci = QTextEdit()
sci.installEventFilter(f)
sci.show()
app.exec_()

So the events (like mouse press) sent to QsciScintilla should always go 
through the event filter first, and if the filter returns true, the 
QsciScintilla should not receive the event.


More information about the QScintilla mailing list