PDA

View Full Version : Check boxes



lupo5
11th May 2014, 02:04
Hi

I want to have a hidden checkbox be checked or unchecked depending on which one of two buttons the user presses.

In the mainwindow.ui I've made a connection from one button to the checkbox and selected "clicked()" for the button and "click()" for the check box.

When I run the program the box checks and unchecks when I click the button. My problem is that the check box begins as checked, but I want it to start off as unchecked. Is there a way I can do this?

So far I've tried:

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QCheckBox checkBox;
checkBox.setChecked( false );

feraudyh
11th May 2014, 11:20
Is your checkbox in the MainWindow?
Whatever window it is in, you could set the checkbox as unchecked in the constructor associated with that window if you know the name of the checkbox. When I look at your code you are just creating
a new checkbox (not the one you want to set). If you created your window with Qt Designer inside Qt Creator you can access the different widgets by typing ui-> inside the editor and the editor will propose the various widget names. When you have found the widget name you can add your call to the constructor like this:
ui->checkBox1.setChecked(false).

anda_skoa
11th May 2014, 12:56
When I run the program the box checks and unchecks when I click the button. My problem is that the check box begins as checked, but I want it to start off as unchecked. Is there a way I can do this?

You can change the initial value even in designer, just change the "checked" property of the checkbox in the property editor.

Cheers,
_