QCheckBoxes
-
Do you use Qt Creator or Qt Designer? You can do this using Qt user-interface.
Otherwise you should create pointers and objects in your ui-class constructor (example from Qt Doc):@
QCheckBox *checkbox = new QCheckBox("Case sensitive", this);
@The best way to use Checkboxes is to use them inside QGroupBox.
Hope it helps. -
Please read "QCheckBox":http://qt-project.org/doc/qt-5.0/qcheckbox.html documentation. QCheckBox inherits "QAbstractButton":http://qt-project.org/doc/qt-5.0/qabstractbutton.html and "QWidget":http://qt-project.org/doc/qt-5.0/qwidget.html so you can add it to a layout as a standard widget.
-
I'd suggest to re-think your GUI design. Do you really expect your users to find their way through 30+ checkboxes on a single page of a wizard? Is that a usable interface?
If you must present that many checkboxes, and they are all on the same level, considder using a list with checkable items. Make sure you add a filter above the list to the user can trim down the list quickly to only the relevant items.
-
I think use dynamic checkboxes.
This is my code, but this is C#.
@private void GenerateDynamicControls(int amount)
{
//Clear existing
pContainer.Controls.Clear();for (int i = 0; i < amount; i++) { //Create the Textbox TextBox dynamicTextbox = new TextBox(); dynamicTextbox.Name = "dynamicTextbox" + i.ToString(); dynamicTextbox.Width = 290; dynamicTextbox.Height = 20; dynamicTextbox.Left = 9; dynamicTextbox.Top = 10 + (dynamicTextbox.Height * i) + (10 * i); //initial + height + padding dynamicTextbox.Text = @"This is textbox number " + (i + 1).ToString(); //Create the Button Button dynamicButton = new Button(); dynamicButton.Name = "dynamicButton" + i.ToString(); dynamicButton.Width = 75; dynamicButton.Height = 23; dynamicButton.Left = dynamicTextbox.Left + dynamicTextbox.Width + 5; dynamicButton.Top = dynamicTextbox.Top; //Center the button vertically to textbox dynamicButton.Text = "Show"; dynamicButton.Click += new EventHandler(Button_Click); //hook the Click event //Add them to the container pContainer.Controls.Add(dynamicTextbox); pContainer.Controls.Add(dynamicButton); } }@
-
Andre said right,36 checkBox in a single form are not good for interface!
but! if you are newbie, u can use this method for generate dynamically controls :
@
for(int i=0;i<37;i++){
QCheckBox *chkbox = new QCheckBox();
chkbox->setText("test");
chkbox->setParent(ui->groupBox);
}
@all of properties can be include in the "for" statement.
have a good code ;)