Changing color of label related to a button
I have multiple buttons and a label related to them which has green color on background. Everytime I click a button the corresponding label shows a yellow border color. I want that everytime I click a button only the corresponding label should change color and the previous clicked should change its color back to normal.
The way I tried is used a signal and slot mechanism for every button click. But the problem is I have to mention the color of not selected labels again and again. I want to reduce this part. Some one please help. Thanks in advance.
The current code is something like this
label1.setStyleSheet("background-color:green;");
label2.setStyleSheet("background-color:green;");
label3.setStyleSheet("background-color:green;");
label4.setStyleSheet("background-color:green;");
connect(button1,SIGNAL(clicked),this,SLOT(button1_ clicked());
connect(button2,SIGNAL(clicked(),this,SLOT(button1 _clicked());
void ClassName::button1_clicked()
{
label1.setStyleSheet("border-width:2px;border-style:solid;border-color:yellow;background-color:green);
label2.setStyleSheet("background-color:green;");
label3.setStyleSheet("background-color:green;");
label4.setStyleSheet("background-color:green;");
}
void ClassName::button2_clicked()
{
label2.setStyleSheet("border-width:2px;border-style:solid;border-color:yellow;background-color:green);
label1.setStyleSheet("background-color:green;");
label1.setStyleSheet("background-color:green;");
label1.setStyleSheet("background-color:green;");