QPushButton check function is not working well
-
Hi Guys!
I dont know where is my mistakes, but I create a QPushbutton and add cilicked event to it. In the cilicked event I checked if the button is checked then i write to debug something and set the pushbutton state to unchecked. And when I clicked the button again the button is checked again... so always checked when i clicked.
So the button:ui->setupUi(this); ui->pushButton->setCheckable(true); ...
And the click event:
void MainWindow::on_pushButton_clicked() { if(ui->pushButton->isChecked()) { qDebug()<<"Checked"; ui->pushButton->setChecked(false); } else { qDebug()<<"UnChecked"; ui->pushButton->setChecked(true); } }
The message is always Checked.
Where is my mistake?
Thanks your help! -
Hi Guys!
I dont know where is my mistakes, but I create a QPushbutton and add cilicked event to it. In the cilicked event I checked if the button is checked then i write to debug something and set the pushbutton state to unchecked. And when I clicked the button again the button is checked again... so always checked when i clicked.
So the button:ui->setupUi(this); ui->pushButton->setCheckable(true); ...
And the click event:
void MainWindow::on_pushButton_clicked() { if(ui->pushButton->isChecked()) { qDebug()<<"Checked"; ui->pushButton->setChecked(false); } else { qDebug()<<"UnChecked"; ui->pushButton->setChecked(true); } }
The message is always Checked.
Where is my mistake?
Thanks your help! -
Hi,
When you click on the button the state changes,
if it checked you set it to false,
so it will be checked again each time you click on it.