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. Regarding Layout Management

Regarding Layout Management

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.3k 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hello All

    I am trying to place below mentioned widgets on my main Window but they are not aligning properly PleaseHELP

    Widgets
    1.GroupBox
    2.In that GroupBox 2 PushButtons & One TableWidget

    Here is my code
    @QGroupBox *TabDialog::createFirstExclusiveGroup()
    {
    QGroupBox *groupBox = new QGroupBox(tr(""));

    QGridLayout *mainLayout = new QGridLayout;

    btnImport = new QPushButton(tr("&Import"));
    btnImport->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
    connect(btnImport, SIGNAL(clicked()), this, SLOT(ImportCSVFile()));

    btnExport = new QPushButton(tr("&Export"));
    btnExport->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
    connect(btnExport, SIGNAL(clicked()), this, SLOT(ExportCSVFile()));

    table = new QTableWidget(3,3);

    mainLayout->addWidget(btnImport, 0, 0 , 1, 2);
    mainLayout->addWidget(btnExport, 0, 1, 1, 2);
    mainLayout->addWidget(table, 0, 1, 1, 2);

    mainLayout->setColumnStretch(0,300);
    mainLayout->setColumnStretch(1, 500);

    groupBox->setLayout(mainLayout);

    return groupBox;
    }@

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      The order you use the calls does not set parents properly.
      Usually, I suggest to give the parent in the constructors:

      @
      QGridLayout *mainLayout = new QGridLayout(groupBox);
      btnImport = new QPushButton(tr("&Import"), groupBox);
      btnExport = new QPushButton(tr("&Export"), groupBox);
      table = new QTableWidget(3,3, groupBox);
      @

      The other possibility is to use the auto reparent feature of the layouts, but then, the parent of the layout must fit, which means the layout must have it's parent before addWidget is called.

      @
      groupBox->setLayout(mainLayout);
      mainLayout->addWidget(btnImport, 0, 0 , 1, 2);
      mainLayout->addWidget(btnExport, 0, 1, 1, 2);
      mainLayout->addWidget(table, 0, 1, 1, 2);
      @

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        ludde
        wrote on last edited by
        #3

        I don't think that's the problem. I always construct layouts that way, and have never had any problems. With Qt 3.x you could run into all kinds of problems if you didn't do things in the right order, but with Qt 4.x it tends to just work, regardless of the order in which you create things and put them in the layouts.

        I think the problem is with the arguments to addWidget. Looks like you are adding btnExport and table in exactly the same place, for example. And btnImport and btnExport are overlapping.

        1 Reply Last reply
        0

        • Login

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