On 13 Nov 2017, at 8:02 pm, VA <[email protected]> wrote:
>
> 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.
So how do you explain the the behaviour of the attached?
Phil
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.Qsci import *
class Filter(QObject):
def eventFilter(self, target, ev):
if ev.type() == QEvent.MouseButtonPress:
print('clicked')
return False
class MyQScintilla(QsciScintilla):
def mousePressEvent(self, ev):
super().mousePressEvent(ev)
ev.ignore()
app = QApplication([])
f = Filter()
#sci = QsciScintilla()
sci = MyQScintilla()
sci.installEventFilter(f)
sci.show()
app.exec_()
_______________________________________________
QScintilla mailing list
[email protected]
https://www.riverbankcomputing.com/mailman/listinfo/qscintilla