closeEvent not working
-
@ZioLupo said in closeEvent not working:
@ewerybody
As I wrote some message after, yes there is -of course - pyside2-uic!Sorry. I didn't see you writing this.
What I just meant is that the name is NOT(with a dash) butpyside2-uic
pyside2uic
without the dash!But I don't like to use it.
Using it solve all of my problems because it produce a class and with the class I can do what I want (inheriting from it, for example).But I would like to avoid to use it
I would always avoid loading ui files directly and compile them only when changed. This way you can easily debug/step through the code. You see the generated structure and you can learn how UIs are written and you can strip a release of the ui files in the end.
-
Just one thing: you are not using
eventFilter
correctly, you don't install it. -
@JonB On PyQt and PyQt5 it works (I've been using it that way) but on Pyside2 it doesn't. Note that I was installing the filters (I just forgot to type it in my previous message). Anyway I ended up using
pyside2-uic
(with a dash) to make my code safer to this issues. -
This post is deleted!
-
is this thing solved?
it's 2021 almost 2022 now.
PySide6 still has the same issue I think.
as far as I know, with pyside6.QtUiTools.QUiLoader(), you can only load ui to an attribute of a shell class e.g. "self.ui" instead of to "self"
which causes some trouble triggering the modified closeEvent method.The type of "self.ui" will still be QMainWindow(depends on what u use). I tried to override closeEvent() but it still won't work that's what confuses me.
Why cant they just add some method to let us load widgets to "self" -_- like "uic.loauUi()" in pyqt
-
@sylvalas Still not solved by the looks of it, at least for me on pyside6, same issue if you load in the ui file (which I want to rather than compile).
However, a workaround exists (https://stackoverflow.com/questions/14834494/pyqt-clicking-x-doesnt-trigger-closeevent), which is to place:
app.aboutToQuit.connect(self.closeEvent)
inside the mainwindow class ( init or another func called when setting up the MW). This is kind of a cheat, as it is not capturing the close event, just the signal that it is about to close, so you cannot decline the event and stop the close. But functionally for me at least it is good enough to allow me to end other processes, safely disconnect hardware and tidy up before the close itself.