PDA

View Full Version : setVisible(bool) problem, only works one way



hojoff79
29th December 2010, 17:50
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



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

nroberts
29th December 2010, 17:53
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?

hojoff79
29th December 2010, 17:59
That was the problem, thank you for your help

wysota
29th December 2010, 18:01
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.