Results 1 to 14 of 14

Thread: widgets behind hidden widgets not working

  1. #1
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default widgets behind hidden widgets not working

    Have you all had this problem? I have two layouts that overlap each other and can be toggled visible via radio buttons. The problem I am seeing is that when I setVisible(false) to my widgets on top and setVisible(true) to widgets on bottom, my bottom widgets are rendered useless. For example, I can't check a check box that was made visible but has a hidden widget on top of it.

    Has anyone ran into this? Is there something I am missing?

    I'll play around with it a little more. If I can get it to work I'll post my solution. Maybe hiding all top widgets first, then making the bottom widgets visible instead of the other way around. Hmmm...

  2. #2
    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: widgets behind hidden widgets not working

    Try using QStackedWidget.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widgets behind hidden widgets not working

    That looks promising except that my widgets are in layouts and I need to stack layouts. I looked at QStackedLayout, which sounds great, but I don't think it accepts layouts either, just widgets.

    There has to be some widget/layout method to call to fix this issue without using another class.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widgets behind hidden widgets not working

    It accepts widgets WITH layouts - meaning that you add all your widgets to container widget that has a layout.

  5. #5
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widgets behind hidden widgets not working

    Augh, I think I see. I am using Qt Designer to create these layouts and what not. So essentially all I do is instantiate a QStackedWidget object and add my widgets? I take it that I call insertWidget(index) and add all of my widgets from layout X to index 1 for example, and all widgets from layout Y to index 2?

    I assume that I can hide my widgets too, by hiding the QStackedWidget object? Or maybe adding a "blank" widget at a certain index and setting the current index it to that index?

    This is cool, thanks for the pointers!

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widgets behind hidden widgets not working

    Augh, I think I see. I am using Qt Designer to create these layouts and what not. So essentially all I do is instantiate a QStackedWidget object and add my widgets? I take it that I call insertWidget(index) and add all of my widgets from layout X to index 1 for example, and all widgets from layout Y to index 2?
    No, you can insert only one widget at a certain index.
    What I meant was that you first create a widget, take layout X and set it to this widget with setLayout. Next add this widget at index 0 and do the same for all your layouts.

    Regards

  7. The following user says thank you to marcel for this useful post:

    bpetty (6th September 2007)

  8. #7
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widgets behind hidden widgets not working

    wow, I am really lost then. If I have 5 widgets in one layout, and 10 widgets in another layout... and I create 15 indexes... how am I suppose to view my 5 widgets at once, then switch over to the other 10 and vice versa? setCurrentIndex() only takes 1 index at a time. I don't want to show one widget at a time, I want to show groups of widgets at a time that happen be in the same location. I guess I don't see how to do this with QStackedWidget.

  9. #8
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: widgets behind hidden widgets not working

    like so:
    Qt Code:
    1. void Window::mkVuBuLayout() // creates a stack of ViewButton layouts
    2. {
    3.  
    4. vuButtStack = new QStackedWidget(this);
    5. vuButtStack->setFixedHeight(34);
    6.  
    7. for(int compNUM=0; compNUM<num_of_stacked_layouts; compNUM++)
    8. {
    9.  
    10. vuButtLayout[compNUM] = new QHBoxLayout;
    11. vuButtLayout[compNUM]->setMargin(0);
    12. vuButtLayout[compNUM]->setAlignment(Qt::AlignLeft);
    13. vuButtLayout[compNUM]->addSpacing(75);
    14.  
    15. for(int i=0; i<num_buttons_in_this_layout; i++)
    16. {
    17. vuButtons[i] = new QPushButton(tr("%1").arg(dafo.get_vuBuNames(i)));
    18. vuButtons[i]->setFixedSize(60,20);
    19. vuButtLayout[compNUM]->addWidget(vuButtons[i]);
    20. vuButtLayout[compNUM]->addSpacing(10);
    21. }
    22.  
    23. vuButtLayoutW[compNUM] = new QWidget(vuButtStack);
    24. vuButtLayoutW[compNUM]->setLayout(vuButtLayout[compNUM]);
    25.  
    26. vuButtStack->addWidget(vuButtLayoutW[compNUM]);
    27.  
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: widgets behind hidden widgets not working

    oops: i posted that before your last post...

    if you have 5 buttons in one layout, and 10 in another: you'll only have 2 indices. Basically, you:

    1. create Q*Layout: lay1

    2. add buttons to lay1

    3. create QWidget: lay1W

    4. do: lay1W->setLayout(lay1);

    5. then do the same with lay2, lay3, etc...

    6. then add these lay*W QWidgets to your QStackedWidget

  11. The following user says thank you to vonCZ for this useful post:

    bpetty (6th September 2007)

  12. #10
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widgets behind hidden widgets not working

    Thanks guys.

    I have ran into an issue though. I am creating my layouts and what not with Qt Designer. My .ui creates the following layout code:

    Qt Code:
    1. // taken from an auto generated ui_*.h file.
    2. QWidget *Layout1;
    3. QHBoxLayout *hboxLayout1;
    4. QLabel *lblDocType_grp1;
    5. QComboBox *cmbIndexes_grp1;
    6. ...
    7. Layout1 = new QWidget(ConfigWidget);
    8. Layout1->setObjectName(QString::fromUtf8("Layout1"));
    9. Layout1->setGeometry(QRect(30, 150, 303, 31));
    10. hboxLayout1 = new QHBoxLayout(Layout1);
    11. hboxLayout1->setSpacing(6);
    12. hboxLayout1->setMargin(0);
    13. hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
    14. lblDocType_grp1 = new QLabel(Layout1);
    15. lblDocType_grp1->setObjectName(QString::fromUtf8("lblDocType_grp1"));
    16.  
    17. hboxLayout1->addWidget(lblDocType_grp1);
    18.  
    19. cmbIndexes_grp1 = new QComboBox(Layout1);
    20. cmbIndexes_grp1->setObjectName(QString::fromUtf8("cmbIndexes_grp1"));
    21. QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(0));
    22. sizePolicy.setHorizontalStretch(0);
    23. sizePolicy.setVerticalStretch(0);
    24. sizePolicy.setHeightForWidth(cmbIndexes_grp1->sizePolicy().hasHeightForWidth());
    25. cmbIndexes_grp1->setSizePolicy(sizePolicy);
    26. cmbIndexes_grp1->setEditable(true);
    27.  
    28. hboxLayout1->addWidget(cmbIndexes_grp1);
    To copy to clipboard, switch view to plain text mode 

    Sooo.. Layout1 is my QWidget that I want to insert right?

    When I create a stacked object like so:
    Qt Code:
    1. void CConfigWidget::InitStack()
    2. {
    3. // Add Layout Widgets to QStackerWidget
    4. pStacker = new QStackedWidget;
    5. pStacker->insertWidget(0, ui.Layout1);
    6. pStacker->insertWidget(1, ui.Layout2);
    7. pStacker->insertWidget(2, ui.Layout3);
    8. }
    To copy to clipboard, switch view to plain text mode 

    and connect it to my radio buttons like so:
    Qt Code:
    1. void CConfigWidget::InitConnections()
    2. {
    3. connect(ui.rbRadio1, SIGNAL(toggled(bool)), this, SLOT(Radio1Click(bool)));
    4. connect(ui.rbRadio2, SIGNAL(toggled(bool)), this, SLOT(Radio2Click(bool)));
    5. connect(ui.rbRadio3, SIGNAL(toggled(bool)), this, SLOT(Radio3Click(bool)));
    6. }
    7.  
    8. void CConfigWidget::Radio1Click(bool bVisible)
    9. {
    10. if (bVisible) pStacker->setCurrentIndex(0);
    11. }
    To copy to clipboard, switch view to plain text mode 

    ... nothing shows up. setCurrentIndex(int) is getting called... but nothing is displayed.

    Am I still missing something?

  13. #11
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: widgets behind hidden widgets not working

    i don't see something like:

    Layout1->setLayout(hboxLayout1);


    ...in the ui_*.h file. Maybe that's it?


    Edit: just saw this in setLayout doc:

    An alternative to calling this function is to pass this widget to the layout's constructor.
    ...so maybe not. (since you did this) But might try it, anyway. I'm not sure what the difference is between:

    Qt Code:
    1. layout = new QHBoxLayout(widget);
    2. //and
    3. layout = new QHBoxLayout;
    4. widget->setLayout(layout);
    To copy to clipboard, switch view to plain text mode 
    Last edited by vonCZ; 7th September 2007 at 08:47.

  14. #12
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widgets behind hidden widgets not working

    What is also odd is that when I setVisible(false) to my top widgets and setVisible(true) to my bottom widgets and then call ->raise() to bring them to the front... that doesn't work either. It is odd. Am I the only one that has had this problem... or just the only one that couldn't get QStackedWidget to work.

  15. #13
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: widgets behind hidden widgets not working

    I got this working. I used QStackedLayout instead. That works great. Not sure why raise() didn't do the trick, but this is a cleaner in my case. Thanks guys. Sorry I was a little slow.

  16. #14
    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: widgets behind hidden widgets not working

    Hmm, you shouldn't need to hide() or raise() anything. It's as simple as this:
    Qt Code:
    1. class Window : public QWidget
    2. {
    3. public:
    4. Window(QWidget* parent = 0) : QWidget(parent)
    5. {
    6. QComboBox* comboBox = new QComboBox(this);
    7. for (int i = 1; i <= 2; ++i)
    8. comboBox->addItem(QString::number(i));
    9.  
    10. QStackedWidget* stackedWidget = new QStackedWidget(this);
    11. stackedWidget->addWidget(createPage1(stackedWidget));
    12. stackedWidget->addWidget(createPage2(stackedWidget));
    13.  
    14. connect(comboBox, SIGNAL(currentIndexChanged(int)), stackedWidget, SLOT(setCurrentIndex(int)));
    15.  
    16. QVBoxLayout* layout = new QVBoxLayout(this);
    17. layout->addWidget(comboBox);
    18. layout->addWidget(stackedWidget);
    19. }
    20.  
    21. private:
    22. QWidget* createPage1(QWidget* parent = 0)
    23. {
    24. ...
    25. }
    26.  
    27. ...
    28. };
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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.