Results 1 to 5 of 5

Thread: Resizing child widget

  1. #1
    Join Date
    Jun 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Resizing child widget

    My project consists of a Main Window displaying a graphical custom widget. I'd like to fill main form with widget frame, and bind together their resizing. Until now I found:

    1. Adding in MainWindow constructor the code

    ui->MyCustomWidget->setGeometry(0,0,this->width(),this->height());

    QBoxLayout *layout = new QBoxLayout(QBoxLayout::LeftToRight,this);
    layout->addWidget(ui->MyCustomWidget);
    this->setLayout(layout);

    So doing child widget fills the parent window but do not resize according to parent resizing (do not change at all).

    2. From designer, right clicking on main form and selecting layout/layout in a grid command. So doing, child resizing works fine but I get an unwanted void frame around the widget.

    3. Subclassing MainWindow::resizeEvent. In such a case widget frame fills completely parent window and resizing works fine.

    Do you know a way to achieve 1 or 2 issues?
    Last edited by drmath; 15th November 2010 at 17:21.

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Resizing child widget

    Do solution nr 2 then select centralWidget, scroll widget properties to bottom to see layout properties then modify layouts margins as you wish.

  3. #3
    Join Date
    Jun 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resizing child widget

    Ok, it works. Any idea about nr 1 issue?

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

    Default Re: Resizing child widget

    Quote Originally Posted by drmath View Post
    Any idea about nr 1 issue?
    You need to set the layout on the central widget and not on the main window widget, it has its own layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resizing child widget

    Ok (if needed we have to add at bottom "layout->setContentsMargins(0,0,0,0);" code to remove void frame around central widget). Thanks

Similar Threads

  1. Automatic resizing of child widgets
    By JovianGhost in forum Newbie
    Replies: 3
    Last Post: 11th March 2010, 12:47
  2. Replies: 7
    Last Post: 14th January 2010, 08:47
  3. Resizing child widget on changing size of parent?
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 13th November 2009, 08:39
  4. Resizing child Widget
    By Pragya in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2007, 06:58
  5. Replies: 14
    Last Post: 19th March 2007, 08:48

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.