setVisible(bool) problem, only works one way
I am trying to set up a function that will make a label visible and invisible on alternating times I push a putton. So far I have set up the connection to use the setVisible(bool) public slot when I push the button. I have set up the function to access ButtonClickedHandler(bool) when action clicked(bool) is taken
Code:
void MainWindow::ButtonClickedHandler(bool checked)
{
ui->label->setVisible(checked);
}
When I compile and run the program, pushing the button the first time makes the label disappear, but pushing it subsequent times does not do anything, and does not turn the visibility back on. How can I get this to work properly?
Alternatively I've tried to just create a connection between the button using clicked(bool) and the label using setVisible(bool), but I have the same exact problem, the first push makes the label disappear but subsequent pushes do not make it return.
Thank you in advance
Re: setVisible(bool) problem, only works one way
Is your button a checkable button? If not then 'checked' is going to always be false. Have you used a debugger to break in that function and see what value it's being supplied with?
Re: setVisible(bool) problem, only works one way
That was the problem, thank you for your help
Re: setVisible(bool) problem, only works one way
In addition to what was already said, use the toggled(bool) signal instead of clicked() as there as situations when clicked() is not emitted and the check state of the button changes.