In Qt, GUI events are handled using the signals and slots features. A signal is emitted from the GUI when an event occurs. Qt widgets have many predefined signals, and users can add custom signals for GUI events. A slot is a function that is called in response to a particular signal. In this example, we are using the clicked() signal of PushButton and creating a custom slot for this signal.
We can write our own code inside this custom function. Let's see how we can create a button, connect a signal to a slot, and convert the entire GUI to Python. Here are the steps involved in creating the Hello World GUI application:
- Drag and create a PushButton from Qt Designer to the empty Form.
- Assign a slot for the button clicked event, which emits a signal called clicked().
- Save the designed UI file in the .ui extension.
- Convert UI files to Python.
- Write the definition of the custom slot.
- Print the Hello World message inside the defined slot/function.
We have already dragged a button from Qt Designer to an empty Form. Press the F4 key to insert a slot on the button. When we press F4, the PushButton turns red, and we can drag a line from the button and place the ground symbol in the main window. This is shown in the following screenshot:
Select the clicked() signal from the left-hand side and click on the Edit... button to create a new custom slot. When we click on the Edit... button, another window will pop up to create a custom function. You can create a custom function by clicking on the + symbol. We created a custom slot called message(), as shown in the following screenshot:
Click on the OK button, save the UI file as hello_world.ui, and quit Qt Designer. After saving the UI file, let's see how we can convert a Qt UI file into a Python file.
Read more about Qt Signals and slots from the following link
https://doc.qt.io/qt-5/signalsandslots.html