I hope you can make a memorandum and correct it.
I think it's easy to want to do some processing only when the application is first displayed, but I can't seem to write MainWindow.show.connect (what a mess).
I searched for how to write onLoad-like processing performed by VBA etc., leaving the description of setupUI generated by Designer as much as possible, and solved it with eventfilter, so please make a memorandum and correct it.
self.startUpFilter = StartUpFilter()
self.centralwidget.installEventFilter(self.startUpFilter)
self.startUpFilter.installWidget(self.hoge,self.fuga)
I found that show events are passed to centralwidget, so I thought that I should set eventfilter to centralwidget and write this and that only at the first show event, but it is passed by eventfilter. Is only the source of the event and the event itself, and I don't know how to operate the hoge and fuga created by Designer from that event, and I can't find it. So, since eventfilter is a class, I thought that it would be better to register the widget itself that will be used later, separately from installEventFilter, so I added a method called installWidget. The completed StartUpFilter is
class StartUpFilter(QtCore.QObject):
startupState = False
def installWidget(self,hoge,fuga):
self.hoge = hoge
self.fuga = fuga
def eventFilter(self, widget, event):
if event.type() == QtCore.QEvent.Type.Show:
if not self.startupState:
self.hoge.hogeMethod(self.fuga)
self.startupState = True
return False
Subclassing hoge and fuga may be the standard. I would like to post a report that it works even if I write it like this, and point out that this is not good.
Recommended Posts