PDA

View Full Version : QGridLayout



ToddAtWSU
28th June 2006, 17:58
I am creating a couple QGLWidgets and displaying them on top of each other. I mean they are above each other on the screen and not actually on top of one another. I use a QGridLayout to align these into 1 column by 'n' rows. I want to be able to double click on any one of these QGLWidgets and allow it to fill the whole screen and then double-click on the full-screen QGLWidget and go back to the previous view of displaying multiple QGLWidgets. I have the slot and signal working correctly because when I double click onto the QGLWidget, I have qDebug statements print out lines before issuing the signal and then inside the slot. But the problem seems to be coming in my handling of the QGridLayout. I create a for-loop that essentially looks like this:


// Written in pseudo-code as the code is on another machine
for( int i = 0 ; i < numQGLWidgets ; i++ )
{
GridLayout->removeWidget( QListOfQGLWidgets[i] );
}

To this point, I believe there should be no widgets remaining in the QGridLayout. Then I go back through the list of QGLWidgets and when it matches the one that sent the signal which is passed in as an argument, I call addWidget like this:


//Again in psuedo-code
for( int i = 0 ; i < numQGLWidgets ; i++ )
{
if( QListOfQGLWidgets[i] == signalEmitter )
{
GridLayout->addWidget( QListOfQGLWidgets[i] );
}
}

But if I click on the first QGLWidget, the OpenGL drawing doubles in size and everything looks like it wants to draw on the entire window, but when you look at the middle of the screen, the second QGLWidget still appears and is still accessible to move and scale. So my question is how do I actually get these other QGLWidgets to disappear and allow the double-clicked QGLWidget to appear over the entire allotted space? Thanks!

wysota
28th June 2006, 22:53
Call QWidget::hide() on all other widgets.

ToddAtWSU
29th June 2006, 14:15
Would hiding these other QGLWidgets cause flicker to occur by hiding them? Would it be more efficient or better to just create a second layout and just call the frame's setLayout() with the new layout? Also, is it just me or should removeWidget( ) actually remove the widget from the layout? If not, what does this function actually do since it does not appear to remove any widgets? Thanks again!

wysota
29th June 2006, 17:24
Would hiding these other QGLWidgets cause flicker to occur by hiding them?
No, it shouldn't cause flicker. Of course it depends how many widgets you actually have there :)

quote]Would it be more efficient or better to just create a second layout and just call the frame's setLayout() with the new layout?[/quote]
It depends whether you want to show all other widgets again. If so, then it's easier to hide them.


Also, is it just me or should removeWidget( ) actually remove the widget from the layout? Yes, it should remove a widget from a layout. Can we see the code you wrote to do it?

Chicken Blood Machine
29th June 2006, 17:57
Also, is it just me or should removeWidget( ) actually remove the widget from the layout? If not, what does this function actually do since it does not appear to remove any widgets? Thanks again!

Yes, the widget will be removed from the layout, but that does not mean that it is removed from the screen. You have to call hide() to do that.

In general, what you are trying to achieve should be easy to do just by causing hide() and show() on the relevant widgets. You should not have to manipulate the layout at all.

ToddAtWSU
29th June 2006, 21:34
Okay, thanks for the help. I have it working now by using hide() and show(). But I will remember that removeWidget() removes it from the layout but not from the screen. Thanks!