QHboxLayout , how to put buttons and checkbox side by side
-
wrote on 24 Apr 2016, 08:40 last edited by
I have a requirement in which I have to place the buttons and check boxes side by side .For that I am using following code
/* creating the refresh button/checkbox at the bottom widget*/
QWidget* bottomWidget = new QWidget;
QHBoxLayout layout = new IN_CURRENT_POOL QHBoxLayout;
bottomWidget->setLayout(layout);
QPushButton button1 = new IN_CURRENT_POOL QPushButton("Button1");
QCheckBox* checkBox1 = new IN_CURRENT_POOL QCheckBox("CheckBox");
QCheckBox *checkBox1 = new IN_CURRENT_POOL QCheckBox("CheckBox2");button1->setMaximumWidth(80);
checkBox1->setMaximumWidth(120);
controlsLayout->addWidget(button1);
controlsLayout->addWidget(checkBox1);
controlsLayout->addWidget(checkBox2);To place it side by side I am using following code as shown above
button1->setMaximumWidth(80);
checkBox1->setMaximumWidth(120);Is ther any other better way to achieve the requirement "I have to place the buttons and check boxes side"
-
I have a requirement in which I have to place the buttons and check boxes side by side .For that I am using following code
/* creating the refresh button/checkbox at the bottom widget*/
QWidget* bottomWidget = new QWidget;
QHBoxLayout layout = new IN_CURRENT_POOL QHBoxLayout;
bottomWidget->setLayout(layout);
QPushButton button1 = new IN_CURRENT_POOL QPushButton("Button1");
QCheckBox* checkBox1 = new IN_CURRENT_POOL QCheckBox("CheckBox");
QCheckBox *checkBox1 = new IN_CURRENT_POOL QCheckBox("CheckBox2");button1->setMaximumWidth(80);
checkBox1->setMaximumWidth(120);
controlsLayout->addWidget(button1);
controlsLayout->addWidget(checkBox1);
controlsLayout->addWidget(checkBox2);To place it side by side I am using following code as shown above
button1->setMaximumWidth(80);
checkBox1->setMaximumWidth(120);Is ther any other better way to achieve the requirement "I have to place the buttons and check boxes side"
wrote on 24 Apr 2016, 12:17 last edited by@Qt-Enthusiast said:
QPushButton button1 = new IN_CURRENT_POOL QPushButton("Button1");
This is not a pointer! This should give already a compile error.
-
wrote on 24 Apr 2016, 15:14 last edited by
Sorry it was a typo I mean
QPushButton* button1 = new IN_CURRENT_POOL QPushButton("Button1");If you could answer my question
-
Sorry it was a typo I mean
QPushButton* button1 = new IN_CURRENT_POOL QPushButton("Button1");If you could answer my question
@Qt-Enthusiast
If I understand correctly what you want to achieve, I'd use a horizontal spacer to eat up the space instead of setting the maximum size for the elements. Something along the lines of:controlsLayout->addWidget(button1); controlsLayout->addWidget(checkBox1); controlsLayout->addWidget(checkBox2); controlsLayout->addStretch(1);
-
Sorry it was a typo I mean
QPushButton* button1 = new IN_CURRENT_POOL QPushButton("Button1");If you could answer my question
wrote on 24 Apr 2016, 15:38 last edited bySorry I thought you had an error when compiling.
I do not see a better solution.
Without going into detail it looks pretty similar to the documentation.. Another possibly to check things is also to use designer and check the files generated by meta compiler.
1/5