How to write what to do when an application is first displayed in Qt for Python with Designer

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

How to write what to do when an application is first displayed in Qt for Python with Designer
What to do when the value type is ambiguous in Python?
[Python] What to do when an error related to SSL authentication is returned
What to do when a warning message is displayed in pip list
[python] What to do when an error occurs in send_keys of headless chrome
What to do if you get an error when installing python with pyenv
Searching for an efficient way to write a Dockerfile in Python with poetry
What to do if abort is displayed when inputting camera video in OpenCV
How to do hash calculation with salt in Python
python: Tips for displaying an array (list) with an index (how to find out what number an element of an array is)
What to do if you get an OpenSSL error when installing Python 2 with pyenv
[Python] What to do when No module named'pyproj.datadir' appears when Exe is done with PyInstaller
What to do when only the window is displayed and nothing is displayed in pygame Note
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if the progress bar is not displayed in tqdm of python
What to do if Python IntelliSense is not displayed in VS Code on Windows
[Learning memo] How to make an application with Django ~ Until Hello World is displayed ~
What to do if you run python in IntelliJ and end with an error
What to do when Japanese is not displayed on matplotlib
How to convert an array to a dictionary with Python [Application]
[Python] How to write an if statement in one sentence.
What to do when an error occurs with import _ssl
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
What to do when there is no response due to Proxy setting in Python web scraping
[Python] How to do PCA in Python
What to do with PYTHON release?
How to not escape Japanese when dealing with json in python
[Beanstalk] What to do when an error occurs with import uuid
How to create a heatmap with an arbitrary domain in Python
How to use an external editor for Python development with Grasshopper
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
How to utilize Python with Jw_cad (Part 1 What is external transformation)
[Python] What is a slice? An easy-to-understand explanation of how to use it with a concrete example.
NameError: global name'dot_parser' is not defined and what to do when it comes up in python
How to do R chartr () in Python
How to work with BigQuery in Python
How to use is and == in Python
How to write Ruby to_s in Python
What to do if there is a decimal in python json .dumps
What to do when the result downloaded via scrapy is in English
What to do if you couldn't send an email to Yahoo with Python.
What to do if No Python documentation found for ... appears in pydoc
What to do if an error occurs when importing numpy with VScode
How to write a string when there are multiple lines in python
When issuing an INSERT statement in Python, no such column is displayed
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
[OSX] [pyenv] What to do when an SSL error occurs in pip
[Mac OS] What to do when Python is not installed as a framework. Is displayed when import matplotlib is performed.
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
What to do if PyInstaller3.5 gives an error in Python3.8 (TypeError: an integer is required (got type bytes))
[What is an algorithm? Introduction to Search Algorithm] ~ Python ~
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
[REAPER] How to play with Reascript in Python
How to do multi-core parallel processing with python
Tips for those who are wondering how to use is and == in Python
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
How to crop an image with Python + OpenCV
What to do when a warning appears around Python integration in Neovim's CheckHealth
Why Docker is so popular. What is Docker in the first place? How to use
How to use tkinter with python in pyenv
What to do when [Errno 2] No such file or directory appears in Python