PDA

View Full Version : QPushButton Red to Green and Green to Red Question



jmqt
22nd July 2009, 14:37
OK. Quick question: When I click on my button it goes from red to green, however, when I want to turn the button off, it does not turn back to red. Does anyone have any suggestions.


button->setChecked(true);

button->setStyleSheet(QString("QPushButton {background-color: red;}"));

connect(button,SIGNAL(pressed()),this,SLOT(onoff() ));
void Dialog::onoff()
{
button->setChecked(false);
button->setStyleSheet(QString("QPushButton {background-color: green;}"));
*
*

wysota
22nd July 2009, 14:50
Yes, use the :pressed pseudo-state.

mcosta
28th July 2009, 08:02
Yes, use the :pressed pseudo-state.
I think :checked pseudo-state is better because the :pressed pseudo-state is on when the mouse button is pressen on the button.