PDA

View Full Version : Grid Layout Problem



Seema Rao
4th May 2006, 13:00
Hi all,

I have problem using Grid Layout. Problem is its taking too much space between columns can some body explain how to remove space? I have attached the problem snap shot and the target look and feel I want Can some body please help

342

343

Here is the code I have written,
first= new QGroupBox("Search details");

QGridLayout *search= new QGridLayout;

QLabel *searchFor= new QLabel("Search for:");
QLabel *within= new QLabel(" Within:");
QLabel *of= new QLabel(" of:");

QComboBox *searchCombo= new QComboBox;
QComboBox *searchCombo1= new QComboBox;
QStringList item1,item2;

item1<< tr(" Palo Alto") << tr("San Jose");
item2<< tr("Centre of Current Map");

searchCombo->addItems(item1);
searchCombo->addItems(item2);

QSpinBox *kiloMeters= new QSpinBox;

kiloMeters->setRange(0,30);
kiloMeters->setSuffix(" km");

search->addWidget(searchFor,0,0);
search->addWidget(searchCombo,0,1);
search->addWidget(within,1,0);
search->addWidget(kiloMeters,1,1);
search->addWidget(of,2,0);
search->addWidget(searchCombo1,2,1);

first->setLayout(search);

I dont know what the problem is ?

wysota
4th May 2006, 13:41
The labels are left aligned and they stretch when you resize the window. Either change size policies of the widgets (both labels and line edits) or provide a spacer which will use up the free space, depending on the effect you want to achieve.

jpn
4th May 2006, 13:45
Change the alignment of the labels to the right:


searchFor->setAlignment(Qt::AlignRight);
within->setAlignment(Qt::AlignRight);
of->setAlignment(Qt::AlignRight);


Then set the combo boxes and the spin box to span applicable amount of columns:


search->addWidget(searchCombo, 0,1,1,3); // span 3 columns
search->addWidget(kiloMeters, 1,1); // span only 1 column
search->addWidget(searchCombo1, 2,1,1,2); // span 2 columns


Finally play with some column stretch factors:


search->setColumnStretch(1, 1);
search->setColumnStretch(2, 2);
search->setColumnStretch(3, 3);