Results 1 to 4 of 4

Thread: Expanding and hiding a widget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Expanding and hiding a widget

    First I want to thank you for your time, I’m new to Qt and I hope I won’t bother you but I have a simple question and I hope I can get a simple answer.

    The circumstances are the following:
    I made a QmainWindow
    That has 1+3 widgets:

    // a main widget
    QWidget *centralWidget;
    //with a main Layout
    QGridLayout *mainLayout;

    //a top Widget (child of centralWidget)
    QWidget *topWidget;
    //with a top Layout
    QGridLayout *topLayout;
    //[…]more childWidgets of topWidget,
    //including a moreButton that when I press it expands middle Widget

    //a middle Widget (child of centralWidget)
    QWidget *middleWidget;
    //with a middle Layout
    QVBoxLayout *middleLayout;
    //[…]more childWidgets of middleWidget;

    //a bottom Widget (child of centralWidget)
    QWidget * bottom Widget;
    //with a bottom Layout
    QHBoxLayout * bottom Layout;
    //[…]more childWidgets of bottom Widget;

    So I hide the middleWidget->hide() in the constructor;

    Then I resize the window so it will start “compressed”
    Qt Code:
    1. QSize size(0, 0);
    2. size = size.expandedTo(mainLayout->minimumSize());
    3. resize(size);
    To copy to clipboard, switch view to plain text mode 

    I connect the more button
    Qt Code:
    1. connect(moreButton, SIGNAL(toggled(bool)),
    2. middleWidget, SLOT(setVisible(bool)));
    To copy to clipboard, switch view to plain text mode 

    and it works well but the problem is that after I made it visible and I hide again the middleWidget the window doesn’t compress back, the MainLayout just covers the empty space left by the middleWidget.

    I even made a SLOT makeSmall that I connected to the moreButton so that it will
    compress again but id doesn't change the size.

    Qt Code:
    1. QSize size(0, 0);
    2. size = size.expandedTo(mainLayout->minimumSize());
    3. this->resize(size);
    To copy to clipboard, switch view to plain text mode 

    If I make the middleLayout visible again the window will keep the same size.

    I want to make the window shrink when I hide the widget but I don't know how how to do it every time I hide the widget (as I sad it compresses at start but afterwards it remains big).

    Sorry if the post is a bit confusing.
    Last edited by Dauntless; 11th December 2006 at 17:37.

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.