-
Notifications
You must be signed in to change notification settings - Fork 0
What We Know About QPushButtons
Table of Contents
A pushbutton or QPushButton is a more or less rectangular area on a GUI that typically:
- has a label like "Push Me"
- causes something to happen when pushed -- like the application get smaller on the screen
- visually seems to push down when clicked and pop back up again when released.
It is a lot like a QLineEdit, but that widget is normally for single line text edit, or QLable which is normally for single line text display. If you want to be clever you can sometimes substitute one for the other, but this is usually a bad idea, QLineEdit and QLable are not really expected to respond to clicks.
Now we will look deeper into the topic of buttons, and talk a bit about how buttons share many features with many other widgets.
After a widget is created we can change may of its characteristics ( and some of these can also be set up in its init, but changing at runtime is a more general process )
These characteristics are part of the widgets state. Some related to appearance. For example:
- size
- font
- colors
Others are related to user actions the widget can detect and act on
- button press
- get focus
Different widget may have different appearance and action states, depending on their intended use.
The code for the tab is: qt5_by_example/tabs/basic_widgets/tab_q_push_button.py at main · russ-hensel/qt5_by_example https://github.com/russ-hensel/qt5_by_example/blob/main/tabs/basic_widgets/tab_q_push_button.py but is better viewed in your own IDE. Also NOTE: this code is our reference for how a tab should be written and is documented by comments in the code, both the framework and the code relavant to the widges of interest. The framework code is not documented as well in other tabs. See Tab Framework Code
Interaction to try on this tab:
- button press
- hover look for tool tips
- poke around -- do not forget to look at the whole GUI for responses.
To see and change the state use the mutate/examine button and read the code in the mutate_x methods.
the documentation is in the code. Coverage is not complete, work continues.
You can use the wat-inspect to find out more or dive into the documentation which is all over the web.
Ask a simulated intelligence ( AI ) Sites like ChatGPT do a pretty good job on QT5. Here is a prompt that we have found useful:
Suppose you are an experienced Python QT5 developer. I need help with a QT5 widget, QPushButton. I would like to modify the widget so that ..( the background color is red )... Can you give me the code that will do that, please include a version that makes the change at create time, and another that makes the modification after the widget is created. Please include error checking code, if applicable.
( May be a bit out of date, these are a pain to keep up. We will not include for other tabs, just run the application )
)