[6.6.1] Custom control panel: possible to turn off one button (Image) when another is clicked/tapped on? Do I use States?
-
Hello, everyone. I didn't know how to summarize the topic title and still have it make sense. My question is regarding using States, or if States is the way I should go.
For some background information, I've created my own custom touch panel (via Adobe Illustrator) to control an LED matrix where I test animations. This project will be used with Python (PySide6) and then used on my Raspberry Pi 4's touchscreen.
I have the images set as buttons, and I've figured out how to get them to change states (On image vs Off image) when clicking on them, but what I cannot figure out (despite looking over all the documentation) is how I can also make a button (technically these are images) turn off when I click/tap on another.
As it stands, I can click on any one of them and able to toggle them all at the same time. What I want is to also include the ability to turn off one of them if I select another. I know AbstractButton and Exclusive ONLY allows turning off one button when another is selected and does not allow toggling that same button; that is not what I want.
Below is a link to my project, which should make it easier to see the code. Currently, I'm using only Main and main to get the basic control panel layout to work how I want before implementing the other files. led_matrix will eventually be linked in to handle the triggering of different animations and control_panelwill have its code merged into main (unless I'm overlooking the fact that I should be using its code with main in order to turn off the other button states?).
-
Hello, everyone. I didn't know how to summarize the topic title and still have it make sense. My question is regarding using States, or if States is the way I should go.
For some background information, I've created my own custom touch panel (via Adobe Illustrator) to control an LED matrix where I test animations. This project will be used with Python (PySide6) and then used on my Raspberry Pi 4's touchscreen.
I have the images set as buttons, and I've figured out how to get them to change states (On image vs Off image) when clicking on them, but what I cannot figure out (despite looking over all the documentation) is how I can also make a button (technically these are images) turn off when I click/tap on another.
As it stands, I can click on any one of them and able to toggle them all at the same time. What I want is to also include the ability to turn off one of them if I select another. I know AbstractButton and Exclusive ONLY allows turning off one button when another is selected and does not allow toggling that same button; that is not what I want.
Below is a link to my project, which should make it easier to see the code. Currently, I'm using only Main and main to get the basic control panel layout to work how I want before implementing the other files. led_matrix will eventually be linked in to handle the triggering of different animations and control_panelwill have its code merged into main (unless I'm overlooking the fact that I should be using its code with main in order to turn off the other button states?).
@I-Mironov is this what you need?
https://doc.qt.io/qt-6/qbuttongroup.html -
@I-Mironov is this what you need?
https://doc.qt.io/qt-6/qbuttongroup.html@JoeCFD No. I guess I should've specifically mentioned that I also looked into the Button group documentation (although I did originally talk about how AbstractButton and Exclusive, which are part of the Button group, will not work for me). Also, trying to make them as buttons completely screws up my entire layout for everything and I can never find helpful answers as to why, but that's a different subject for another time.
All I want to know is if it is possible with my current setup. If yes, how do I go about it? If no, why?
.
.
.
UPDATE: I found out that it is indeed possible, and it was incredibly simple! All I had to do was include some additional onClicked handlers to set the states of the other buttons to off.Before:
MouseArea { anchors.fill: parent onClicked: leftSignal.buttonState = (leftSignal.buttonState === 'on') ? 'off' : 'on'; }
After:
MouseArea { anchors.fill: parent onClicked: { rightSignal.buttonState = 'off'; brakeLights.buttonState = 'off'; parkingLights.buttonState = 'off'; leftSignal.buttonState = (leftSignal.buttonState === 'on') ? 'off' : 'on'; } }
-