Solved QPushButton background
-
Hi guys. I'm using Qt5 c++ to create Dashboard user panel.
I want to change a background of a button when it's selected until I click in another button.
I had a look to a Qt documentation, but I didn't find such signal in QPushButton nor in QAbstractButton.
Anyone can help me? -
Use Stylesheet:
setStyleSheet("QPushButton#YourButton { background:Some_Color; }");
@delilong1 said in QPushButton background:
when it's selected
Selected? You mean
hasFocus
? Or what kind of button do you have? -
@Pl45m4 Yeah. But I want the background color to be changed after I clicked the button and until I click another button. Then the background-color is passed the last button I clicked over. "As in a navigation bar indicating which button is displaying a content of my application"
-
Hi
What you can do is to create QButtonGroup and add the QPushButtons to it.
If using UI files you can just select all buttons and right click and add it.
Else it must be done in code.
https://doc.qt.io/qt-5/qbuttongroup.html-
For each button set the CheckAble to true
-
then apply a style sheet to the form holding the buttons
QPushButton { background-color: white; border: none; } QPushButton:checked { background-color: red;}
- then it should work as you want
-
-
@mrjj Thank you very much!!! . That's what I need
-
@delilong1
np :)
Do notice that there are signals for the button being checked or unchecked just like the
ones for clicked if you need to do stuff when its checked.
But the normal clicked signal still works so might not be needed. -
@mrjj Yep. And I try it with focus like in CSS. It's still working too.
QPushButton:focus{background-color:rgb(int, int, int);}
I don't know if there is some problem using it -
Hi
if it looks like you want no issues. :)https://doc.qt.io/qt-5/stylesheet-reference.html
"List of Pseudo-States"
show the states Qt knows. Its not full CSS -
@mrjj 👍. Thanks