Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Coding objects in GroupBox in a main layout
Forum Updated to NodeBB v4.3 + New Features

Coding objects in GroupBox in a main layout

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kaiser0792
    wrote on 23 Oct 2011, 22:57 last edited by
    #1

    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>

    GameDialog::GameDialog(QWidget parent) :QDialog(parent)
    {
    // Create and configure layouts
    QVBoxLayout
    mainLayout = new QVBoxLayout(this);
    QGridLayout* gridLayout = new QGridLayout;
    QVBoxLayout* groupBoxLayout = new QVBoxLayout;

    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);
            }
    
    groupBox = new QGroupBox("Simulation Configuration");
    groupBoxLayout->addWidget(groupBox);
    numStepsLabel = new QLabel("Number of Steps");
    groupBoxLayout->addWidget(numStepsLabel);
    

    }@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mkoskim
      wrote on 23 Oct 2011, 23:40 last edited by
      #2

      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:

      [code]
      // Make grid
      QGridLayout *gridLayout = ...

      for(int i = 0; ...) ... gridLayout->addWidget(toolButton, i, j);

      // Make groupbox and set layout
      groupBox = new QGroupBox;
      QVBoxLayout groupBoxLayout = new QVBoxLayout;
      groupBox->setLayout(groupBoxLayout);

      // Add things to groupbox (via layout)
      groupBoxLayout->addLayout(gridLayout);
      groupBoxLayout->addWidget(new QLabel);
      [/code]

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

      http://mkoskim.wordpress.com
      http://mkoskim.drivehq.com
      http://mkoskim.deviantart.com

      1 Reply Last reply
      0

      1/2

      23 Oct 2011, 22:57

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved