Creating A Minimal Application - russ-hensel/qt5_by_example GitHub Wiki
Much of this book is a reference that goes through QT one widget at a time. But one widget does not make an application, it takes a village. Explaining the whole village is a lot of explaining, so we ask you to take it as a bit of magic, or as a template you will just copy/imitate until you understand the content better.
An outline is that we need:
- an Application
- a Main Window
- some Widgets as a place on the Main Window to put other widgets
- Widgets like buttons and line edits, with some properties and behaviours
- Widget like buttons.... need to be put on the window with a layout manager.
All the details are in the code.
Another cut at this in case repetition helps:
Of course this toolkit is about graphical user interfaces so we will need an application and a window to put the interface on.
And to add just a bit more content we will add a button and a line edit, but put off the discussion of them till later.
We are trying to cover qt widget by widget, but to get going we need a whole set of widgets QApplication, QWidget, QHBoxLayout.... Try not to obsess over understanding everything at once. Try to accept the background code and focus on one widget at at time.
The process of creating an application is a bit mystic/magical but not difficult. I asked a chatbot how to do it then modified it for my style of qt applications.
Here is what i got:
https://github.com/russ-hensel/qt5_by_example/blob/main/basic_app.py
you should open it in some IDE ( Spyder would be Best), read it, and run it.
The basic idea is to create an application thing: app = QApplication... this can take arguments but so far I have never used them.
and after the application is created create a window: MainWindow. init( ) this is where the widgets live
we run it with a bit more code ..... app.exec_() .....
In MainWindow there is some code about a central widget.... and other stuff. For now just treat it as magic and threat this code as a template -- copy it to start your own apps.
So for now that is about all we will cover in this "tutorial".
In the future if you want an application: copy this code as a template and then build on it. We will cover many more details as we go along -- the next being a bit more about that button ?? perhaps.
lesson