PDA

View Full Version : Re: How to change the colour of a pushbutton when disabled[SOLVED]



duma
15th August 2011, 19:09
I have 2 pushButtons. The following code disables a pushButton when clicked and enables the other one. I would like to change the colour of the pushButtons when they are disabled(to gray). How do I do this? Any help would be appreciated.


void wave::on_pushButton_clicked()
{
//Generate
thread->start();
ui->pushButton->setEnabled(false);
ui->pushButton_2->setEnabled(true);
}

void wave::on_pushButton_2_clicked()
{
//Terminate
thread->terminate();
ui->pushButton_2->setEnabled(false);
ui->pushButton->setEnabled(true);

}

Added after 12 minutes:

got it actually:

void wave::on_pushButton_clicked()
{
//Generate
freq = ui->frequency->text().toDouble();
ampl = ui->amplitude->text().toDouble();
thread->start();
ui->pushButton->setEnabled(false);
ui->pushButton->setStyleSheet("background-color: gray");
ui->pushButton_2->setStyleSheet("background-color: rgb(255, 192, 192)");
ui->pushButton_2->setEnabled(true);
}

void wave::on_pushButton_2_clicked()
{
//Terminate
thread->terminate();
ui->pushButton_2->setEnabled(false);
ui->pushButton_2->setStyleSheet("background-color: gray");
ui->pushButton->setStyleSheet("background-color: rgb(192, 255, 208);");
ui->pushButton->setEnabled(true);

}