Solved Use uic.loadUi and get mouseMoveEvent
-
Hi!
I useclass MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.ui = uic.loadUi("mainWindow.ui")
How I can get mouseMoveEvent from "mainWindow.ui"?
-
@Mikeeeeee
OverridemouseMoveEvent()
. Or install an event filter viainstallEventFilter()
. -
@JonB said in Use uic.loadUi and get mouseMoveEvent:
Or install an event filter via installEventFilter().
Please give an example of how to do this
-
@Mikeeeeee There are enough examples in Qt documentation.
https://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.html -
@jsulm said in Use uic.loadUi and get mouseMoveEvent:
There are enough examples in Qt documentation.
https://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.htmlThere is no installEventFilter in this example
-
@Mikeeeeee There is example for mouseMoveEvent
But I again did the search for you (no idea why you can't): https://doc.qt.io/qt-5/qobject.html#installEventFilter -
@jsulm said in Use uic.loadUi and get mouseMoveEvent:
There is example for mouseMoveEvent
But I again did the search for you (no idea why you can't): https://doc.qt.io/qt-5/qobject.html#installEventFilterI saw it.
It is not work:self.installEventFilter(self.ui)
def eventFilter(self, object, event): print(111111111111111)
-
-
How do I get the events from the self.ui?
-
@Mikeeeeee Install event filter there, probably like (I don't use Qt with Python):
self.ui.installEventFilter(myEventFilter)
where myEventFilter is your event filter object (like keyPressEater in the example).
-
@jsulm said in Use uic.loadUi and get mouseMoveEvent:
lf.ui.installEventFilter(myEventFilter)
Documentation:
void QObject::installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object. For example:monitoredObj->installEventFilter(filterObj);
Your code will not work, you need to put an object in the function argument. I still need an example.
-
@Mikeeeeee said in Use uic.loadUi and get mouseMoveEvent:
our code will not work, you need to put an object in the function argument.
That's exactly what I'm doing:
self.ui.installEventFilter(myEventFilter)
I even wrote: "where myEventFilter is your event filter object"!
So, why do you think it will not work? Did you try? I have no idea what other example you need, I'm out of this thread... -
@jsulm said in Use uic.loadUi and get mouseMoveEvent:
myEventFilter
I don't understand you. Please give a full-fledged example.
-
It is work
self.ui.installEventFilter(self)
-
@Mikeeeeee said in Use uic.loadUi and get mouseMoveEvent:
Please give a full-fledged example.
I will not.
class MyEventFilter(QObject): def eventFilter(QObject obj, QEvent event): print("HERE") return QObject::eventFilter(obj, event) ... myEventFilter = MyEventFilter() self.ui.installEventFilter(myEventFilter)