Results 1 to 3 of 3

Thread: Why doesnt my QGridLayout resize?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Why doesnt my QGridLayout resize?

    This resizes perfectly ------
    Qt Code:
    1. QGridLayout *layout = new QGridLayout(this);
    2. layout->setSpacing(6);
    3. layout->setMargin(11);
    4. QPlainTextEdit* mybox = new QPlainTextEdit(this);
    5. layout->addWidget(mybox, 0, 0, 1, 2);
    6. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

    This doesnt resize at all ------
    Qt Code:
    1. QWidget* widget = new QWidget(this)
    2. QGridLayout *layout = new QGridLayout(widget);
    3. layout->setSpacing(6);
    4. layout->setMargin(11);
    5. QPlainTextEdit* mybox = new QPlainTextEdit(this);
    6. layout->addWidget(mybox, 0, 0, 1, 2);
    7. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

    The only difference is with the 2nd example, im creating a widget* and making the layout a child of that widget which is what Qt Designer does.. How can I make this resize work using the 2nd example?
    Last edited by jpn; 20th January 2009 at 07:16. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why doesnt my QGridLayout resize?

    Try:

    Qt Code:
    1. QGridLayout *layout = new QGridLayout(widget);
    2. QWidget* widget = new QWidget(this);
    3. layout->setSpacing(6);
    4. layout->setMargin(11);
    5. QPlainTextEdit* mybox = new QPlainTextEdit(this);
    6. layout->addWidget(mybox, 0, 0, 1, 2);
    7. layout->addWidget(widget, 0, 0, 1, 3); //<--or whatever you need
    8. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Why doesnt my QGridLayout resize?

    QLayout constructor already calls QWidget::setLayout(). So the following code doesn't make sense:
    Qt Code:
    1. QGridLayout *layout = new QGridLayout(widget);
    2. ...
    3. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 
    First you install the layout on "widget", then you attempt to install the same layout on "this".
    J-P Nurmi

Similar Threads

  1. Replies: 2
    Last Post: 22nd January 2008, 16:10
  2. QGraphicsScene / QGraphicsView speed after resize
    By themolecule in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2007, 23:46
  3. Qt 3.3 QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2007, 17:40
  4. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00
  5. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32

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
  •  
Qt is a trademark of The Qt Company.