You don't need to connect the signal and the slot, if you name your function "on__" in this case "on_one_btn_clicked" qt connect them automatically, this is nice because enforces consistency among multiple programmers and avoid bloat on the code.
1st Class tutorial. Nicely done Derek! Qt & I go back well over 15 years (C++ & Qt Creator), and pyQt maybe 8 years give or take... it just never gets old!
I like to name like this: (assuming a button) btn_button_name. That way if I forget what the button is called it's very easy to bring up the autocomplete and see a list of every button just by typing "btn". I find it much easier to remember the type of control I'm looking for instead of the name and once I narrow down the lists to types it's usually pretty obvious which specific buttons (or other types) I'm looking for.
Why not using PySide which is an official Qt project and probably has more maintainers? The interface and syntax is similar and even more pythonic. Loading ui files directly is easier. Only disadvantage is not having a py file for type hints and annotations. But do vim users even know what they're missing 😀
If you want a python script to run in headless mode (w/o console output) you can change the extension to .pyw instead of .py. Obvs your xmonad hides that stuff anyway but might be good for hiding your script's console output from your users.
I'm trying to dig into python and qt because I want to write an application. So, to sum it up... this method is preferred because: 1) you don't generate a bloated ui file 2) you can make changes on the fly without having to rebuild the ui file is that correct? so, does the method DT showed in the previous video has its advantages? Btw, thanks as always for your videos DT, you're the best!
That is correct, I don't think the previous method has any advantages, you can still add custom widgets in a dynamic way if you like after loadUI. For instance, I leave empty frames in designer then I add matplotlib plots to them in init.
qt designer and PyQt are great; but I don't really like using pyuic and prefer to import .ui files at runtime. Indeed, it gives a better separation between the UI and the code and is simpler to maintain over time. Of course, this is only usefull if we use Qt Designer.. Direct coding the ui in PyQt is also a option but I usually find it frustrating...
I made a separate python script that calls pyuic and compiles all the files in a specified directory into a different output directory in my project. This way the python code is available in the editor (VS code in my case) allowing it to offer autocomplete on widgets names defined within the UI. This saves me a lot of time/effort because I don't have to meticulously make sure I got the object name right, I choose it from a list and the editor makes it match verbatim! I usually create a controller script for each UI that handles separating the UI from the logic. The controller is also a good place to make slight tweaks to the UI that the designer doesn't allow for (like setting window flags). All I have to do when tweaking the UI is edit the ui file in designer then call my compile script and my app is ready to go (granted deleting things or changing object names may mean you have to make alterations to the controller but your main logic will be unaffected)
just rename your buttons the other way. btn_one ... With intellisense when you hit bt all your buttons are grouped together to choose the one you want.
Unfortunately using the uncompiled .ui file means that no editor will actually be able to give the type hints. That said if you are using the .py compiled version starting with 'btn_' is the way to go!!!
This should be a series.
You don't need to connect the signal and the slot, if you name your function "on__" in this case "on_one_btn_clicked" qt connect them automatically, this is nice because enforces consistency among multiple programmers and avoid bloat on the code.
I did not know this, this is nice.
1st Class tutorial. Nicely done Derek! Qt & I go back well over 15 years (C++ & Qt Creator), and pyQt maybe 8 years give or take... it just never gets old!
Really nice video DT!
I like to name like this: (assuming a button) btn_button_name.
That way if I forget what the button is called it's very easy to bring up the autocomplete and see a list of every button just by typing "btn". I find it much easier to remember the type of control I'm looking for instead of the name and once I narrow down the lists to types it's usually pretty obvious which specific buttons (or other types) I'm looking for.
Why not using PySide which is an official Qt project and probably has more maintainers? The interface and syntax is similar and even more pythonic.
Loading ui files directly is easier. Only disadvantage is not having a py file for type hints and annotations. But do vim users even know what they're missing 😀
12:14 if you are feeding script to python executable like that, chmod +x does nothing in that case
He needs to add the Shebang to his script. It drives me crazy when people don't have a shebang in their scripts.
@@DigitalMetalagreed I feel thr same
If you want a python script to run in headless mode (w/o console output) you can change the extension to .pyw instead of .py. Obvs your xmonad hides that stuff anyway but might be good for hiding your script's console output from your users.
I'm trying to dig into python and qt because I want to write an application. So, to sum it up... this method is preferred because:
1) you don't generate a bloated ui file
2) you can make changes on the fly without having to rebuild the ui file
is that correct? so, does the method DT showed in the previous video has its advantages?
Btw, thanks as always for your videos DT, you're the best!
That is correct, I don't think the previous method has any advantages, you can still add custom widgets in a dynamic way if you like after loadUI. For instance, I leave empty frames in designer then I add matplotlib plots to them in init.
u mean dtos spin not distro
qt designer and PyQt are great; but I don't really like using pyuic and prefer to import .ui files at runtime. Indeed, it gives a better separation between the UI and the code and is simpler to maintain over time. Of course, this is only usefull if we use Qt Designer.. Direct coding the ui in PyQt is also a option but I usually find it frustrating...
I made a separate python script that calls pyuic and compiles all the files in a specified directory into a different output directory in my project. This way the python code is available in the editor (VS code in my case) allowing it to offer autocomplete on widgets names defined within the UI. This saves me a lot of time/effort because I don't have to meticulously make sure I got the object name right, I choose it from a list and the editor makes it match verbatim!
I usually create a controller script for each UI that handles separating the UI from the logic. The controller is also a good place to make slight tweaks to the UI that the designer doesn't allow for (like setting window flags).
All I have to do when tweaking the UI is edit the ui file in designer then call my compile script and my app is ready to go (granted deleting things or changing object names may mean you have to make alterations to the controller but your main logic will be unaffected)
you and your custom linux are fuking amazing.
What was the rufi them u where using for your search. Loved the sound effect too
just rename your buttons the other way. btn_one ... With intellisense when you hit bt all your buttons are grouped together to choose the one you want.
Unfortunately using the uncompiled .ui file means that no editor will actually be able to give the type hints. That said if you are using the .py compiled version starting with 'btn_' is the way to go!!!
Hello DT. Is your code on line on your gitlab? 😊
what kinda OS are you using ?
Qt designer is not free
Of course it is free. It is such a crap that no one would pay for it.
"Python is a real language". :P :P :P