Results 1 to 5 of 5

Thread: Hide contents of different layouts

  1. #1
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Hide contents of different layouts

    I have created several QGridLayout and put different labels and other widgets in these. As I choose an option in a QComboBox, I will hide all layouts but the one I have chosen, i.e. show different set of widgets for different options.

    I have tried this:
    Qt Code:
    1. test_layout = new QGridLayout();
    2. test_layout->setColumnStretch(0,1);
    3. test_labelOne = new QLabel("Angle");
    4. test_labelOne->setParent(test_layout);
    5. test_layout->addWidget(test_labelOne, 0, 1);
    To copy to clipboard, switch view to plain text mode 

    For then later traverse the test_layout->children() to set visibility on these children.

    This gives me the compile-error:
    ConfigureDlg.cpp:520: error: no matching function for call to âQLabel::setParent(QGridLayout*&)â
    /usr/local/Trolltech/Qt-4.5.0-rc1/include/QtGui/qwidget.h:527: note: candidates are: void QWidget::setParent(QWidget*)
    /usr/local/Trolltech/Qt-4.5.0-rc1/include/QtGui/qwidget.h:528: note: void QWidget::setParent(QWidget*, Qt::WindowFlags)

    Any suggestions?

    setParent(QObject*) is a function in QObject. and setParent(QWidget*) is a function in QWidget, but QWidget inherits QObject. Shouldn't it be available?

    What I really try to accomplish is to have several set of layouts and hide and show these on demand to get a more clean code.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Hide contents of different layouts

    Hi,

    couldn't you just delete row 4 with the set setParent? And how is test_layout defined? Maybe you have forgotten the "*":
    Qt Code:
    1. QLabel::setParent(QGridLayout*&)
    To copy to clipboard, switch view to plain text mode 
    isn't right because it only will accept
    Qt Code:
    1. QLabel::setParent(QGridLayout*)
    To copy to clipboard, switch view to plain text mode 

    Lykurg

  3. #3
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Hide contents of different layouts

    Found a solution:

    Qt Code:
    1. void ConfigureDlg::showChildren(const QGridLayout* layout, bool show)
    2. {
    3. QLayoutItem *item = 0;
    4. QWidget *widget = 0;
    5.  
    6. for(int i = 0; i < layout->rowCount(); ++i)
    7. {
    8. for(int j = 0; j < layout->columnCount(); ++j)
    9. {
    10. item = layout->itemAtPosition(i,j);
    11. widget=item?item->widget():0;
    12. if(widget)
    13. widget->setVisible(show);
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    item->widget() is a type safe casting function that returns 0 if the item is not a QWidget.

    Each subset of tools are added to their own QGridLayout and all these layouts are added to a layout in my dialog widget with the same position.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Hide contents of different layouts

    Wow, better you apply the layout to a QWidget/QFrame etc. and hide/show this.

  5. #5
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Hide contents of different layouts

    Quote Originally Posted by Lykurg View Post
    Wow, better you apply the layout to a QWidget/QFrame etc. and hide/show this.
    Ah. That was probably what I was looking for in the first place. But then I got another layer and some margins that need to be set, so I'll probably stick with my method now that I've already coded it.

Similar Threads

  1. Replies: 10
    Last Post: 20th April 2015, 22:24
  2. Replies: 0
    Last Post: 17th April 2009, 08:58
  3. Complex button contents
    By spraff in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2008, 15:17
  4. Problems putting layouts inside groupbox
    By conexion2000 in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 10:01
  5. 2 Questions about layouts
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2006, 13:54

Tags for this Thread

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.