Results 1 to 3 of 3

Thread: Grid Layout Problem

  1. #1
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Grid Layout Problem

    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

    problem..gif

    target.gif

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Grid Layout Problem

    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.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Grid Layout Problem

    Change the alignment of the labels to the right:
    Qt Code:
    1. searchFor->setAlignment(Qt::AlignRight);
    2. within->setAlignment(Qt::AlignRight);
    3. of->setAlignment(Qt::AlignRight);
    To copy to clipboard, switch view to plain text mode 

    Then set the combo boxes and the spin box to span applicable amount of columns:
    Qt Code:
    1. search->addWidget(searchCombo, 0,1,1,3); // span 3 columns
    2. search->addWidget(kiloMeters, 1,1); // span only 1 column
    3. search->addWidget(searchCombo1, 2,1,1,2); // span 2 columns
    To copy to clipboard, switch view to plain text mode 

    Finally play with some column stretch factors:
    Qt Code:
    1. search->setColumnStretch(1, 1);
    2. search->setColumnStretch(2, 2);
    3. search->setColumnStretch(3, 3);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. qdirmodel in grid layout
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 27th July 2008, 09:26
  2. Grid Problem
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2007, 11:40
  3. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 02:37
  4. Dynamic grid layout
    By eriwik in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2006, 16:19
  5. Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 4
    Last Post: 19th April 2006, 12:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.