Coding objects in GroupBox in a main layout
I’m creating a Dialog for which I have created a main layout. I have added a 2D array of toolbuttons to the Dialog and next need to create a GroupBox that contains a few child widgets. To get the GroupBox to show up on the Dialog, I’ve had to add it to a SubLayout. But when I try to write code that places child widgets in the GroupBox, they show up outside the GroupBox. I have worked on this all day and have tried several variations suggested by the Qt Documentation examples. . Below is the code that I have written so far, it just attempts to add a QLabel to the GroupBox. Thanks for any help in advance.
- #include "gamedialog.h"
- #include <QtGui>
- {
- // Create and configure layouts
- mainLayout->addLayout(gridLayout);
- mainLayout->addLayout(groupBoxLayout);
- mainLayout->addStretch();
- // Create grid of toolbuttons and add to layout
- const int ROWS = 11;
- const int COLUMNS = 21;
- for(int i = 0; i < ROWS; i++)
- for(int j = 0; j < COLUMNS; j++)
- {
- toolButton = new QToolButton;
- gridLayout->addWidget(toolButton, i, j);
- }
- groupBoxLayout->addWidget(groupBox);
- groupBoxLayout->addWidget(numStepsLabel);
- }
1 reply
Well, I’m not sure what you meant, but if you want your gridLayout (containing those toolbuttons) to be inside groupBox, shouldn’t you put the gridLayout inside your groupBox? Something like this:
- // Make grid
- for(int i = 0; ...) ... gridLayout->addWidget(toolButton, i, j);
- // Make groupbox and set layout
- groupBox = new QGroupBox;
- groupBox->setLayout(groupBoxLayout);
- // Add things to groupbox (via layout)
- groupBoxLayout->addLayout(gridLayout);
…And then put groupBox to dialog?
EDIT: I mean, it seems that you add your grid to main layout (line 12), and not in your groupbox’s layout.
You must log in to post a reply. Not a member yet? Register here!
