Results 1 to 3 of 3

Thread: Check boxes

  1. #1
    Join Date
    May 2014
    Posts
    4
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Check boxes

    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:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. QCheckBox checkBox;
    6. checkBox.setChecked( false );
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Check boxes

    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).

  3. The following user says thank you to feraudyh for this useful post:

    lupo5 (11th May 2014)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Check boxes

    Quote Originally Posted by lupo5 View Post
    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,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    lupo5 (11th May 2014)

Similar Threads

  1. QAbstractItemView and tri state check boxes
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 3rd June 2011, 07:54
  2. Best class for pop up boxes
    By denumbaone in forum Newbie
    Replies: 3
    Last Post: 14th March 2011, 21:56
  3. Qt tree widget with check boxes iteration
    By denton17 in forum Newbie
    Replies: 1
    Last Post: 9th November 2010, 14:24
  4. Resizable layout boxes
    By NOR in forum Newbie
    Replies: 3
    Last Post: 16th April 2008, 14:48
  5. List withembedded check boxes
    By bruccutler in forum Newbie
    Replies: 3
    Last Post: 7th March 2007, 18:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.