September 7, 2011

Leon Leon
Robot Herder
416 posts

[SOLVED] Problem with mainLayout of Dialog.

 

I have a problem with the mainLayout. I have this:

  1.  optionsGroupBox = new QGroupBox();
  2.     optionsGroupBoxLayout = new QGridLayout;
  3.     optionsGroupBoxLayout->addWidget(ui->label, 0,0);
  4.     optionsGroupBoxLayout->addWidget(ui->comboBox, 0,1);
  5.     optionsGroupBoxLayout->addWidget(ui->label_2, 1,0);
  6.     optionsGroupBoxLayout->addWidget(ui->lineEdit, 1,1);
  7.     optionsGroupBoxLayout->addWidget(ui->label_3, 2,0);
  8.     optionsGroupBoxLayout->addWidget(ui->lineEdit_2, 2,1);
  9.     optionsGroupBoxLayout->addWidget(ui->pushButton_3, 2,2);
  10.  
  11.     optionsGroupBox->setLayout(optionsGroupBoxLayout);
  12.  
  13.     buttonsLayout = new QHBoxLayout;
  14.     buttonsLayout->addStretch();
  15.     buttonsLayout->addWidget(ui->pushButton_2);
  16.     buttonsLayout->addWidget(ui->pushButton);
  17.  
  18.     mainLayout = new QVBoxLayout;
  19.     mainLayout->addWidget(optionsGroupBox);
  20.     mainLayout->addLayout(buttonsLayout);
  21.     setLayout(mainLayout);

and it looks like:
screen
but i want it look like:
screen2

So the question
What about the space up from the button Browze.. How can it be covered from the above linedit? ( See second screenshot )
Thanks for any answers :)

P.S When i say the space up from the button Browze i mean:
screen3

5 replies

September 7, 2011

goblincoding goblincoding
Robot Herder
200 posts

Leon wrote:
I have a problem with the mainLayout. I have this:

  1.  optionsGroupBox = new QGroupBox();
  2.     optionsGroupBoxLayout = new QGridLayout;
  3.     optionsGroupBoxLayout->addWidget(ui->label, 0,0);
  4.     optionsGroupBoxLayout->addWidget(ui->comboBox, 0,1);
  5.     optionsGroupBoxLayout->addWidget(ui->label_2, 1,0);
  6.     optionsGroupBoxLayout->addWidget(ui->lineEdit, 1,1);
  7.     optionsGroupBoxLayout->addWidget(ui->label_3, 2,0);
  8.  
  9.     //add an additional layout for the Browse button and second line edit
  10.     QVBoxLayout lineAndBrowseLayout = new QVBoxLayout;
  11.     lineAndBrowseLayout->addWidget(ui->lineEdit_2);
  12.     lineAndBrowseLayout->addWidget(ui->pushButton_3);
  13.     optionsGroupBoxLayout->addLayout(lineAndBrowseLayout, 2,1);*
  14.  
  15.     optionsGroupBox->setLayout(optionsGroupBoxLayout);
  16.  
  17.     buttonsLayout = new QHBoxLayout;
  18.     buttonsLayout->addStretch();
  19.     buttonsLayout->addWidget(ui->pushButton_2);
  20.     buttonsLayout->addWidget(ui->pushButton);
  21.  
  22.     mainLayout = new QVBoxLayout;
  23.     mainLayout->addWidget(optionsGroupBox);
  24.     mainLayout->addLayout(buttonsLayout);
  25.     setLayout(mainLayout);
The bit I added above should do the trick. Note, however, that the space available to position (2,1) in the grid (where we’re adding the new layout) will be divided equally between the line edit and the Browse button, i.e. they’ll be the same size. You may have to play around with constraints a bit to get your ratio of QLineEdit::QPushButton space usage just right.

September 7, 2011

Lukas Geyer Lukas Geyer
Dinosaur Breeder
2074 posts

There is a QGridLayout::addWidget() overload which takes a rowSpan and a columnSpan too.

  1. optionsGroupBoxLayout->addWidget(ui->comboBox, 0,1,1,2);
  2. optionsGroupBoxLayout->addWidget(ui->lineEdit, 1,1,1,2);

Will do the trick.

September 7, 2011

Leon Leon
Robot Herder
416 posts

k the first answer is ok! :D
Just not QVBoxLayout lineAndBrowseLayout = new QVBoxLayout;
but lineAndBrowseLayout = new QHBoxLayout
will do what i want.. thanks ;)

September 8, 2011

goblincoding goblincoding
Robot Herder
200 posts

I don’t know why, but I always do that! It’s like a mini brain rebellion over which I have no control :D

September 8, 2011

Andre Andre
Area 51 Engineer
6076 posts

On a side-note. The word is “Browse”, not “Browze”. You also might want to check if you really want to say “Nami”.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

 
  ‹‹ Stacked and TabWidget      Qt Mobility API’s in Qt SDK ››

You must log in to post a reply. Not a member yet? Register here!