Qt-interest Archive, December 2007
Blocking updates.
Message 1 in thread
Dear trolls,
I have a layout containing, say, 10 widgets. 4 are visible at a time,
and I have buttons that allow to "scroll"
inside the list of widgets. I hide() and show() the corresponding
widgets. The problem is that at some point
I show() a 5th widget just before hiding another, resulting in some
annoying flickering. I tried to use
setUpdatesEnabled() before and after the modifications but it does not
change anything. Is there a way to
handle this problem ? Any hint ?
Best regards,
Alex
--
[ signature omitted ]
Message 2 in thread
On tirsdag den 4. December 2007, Alexandre Beraud wrote:
> I have a layout containing, say, 10 widgets. 4 are visible at a time,
> and I have buttons that allow to "scroll"
> inside the list of widgets. I hide() and show() the corresponding
> widgets. The problem is that at some point
> I show() a 5th widget just before hiding another, resulting in some
> annoying flickering. I tried to use
> setUpdatesEnabled() before and after the modifications but it does not
> change anything. Is there a way to
> handle this problem ? Any hint ?
Unfortunately, setUpdatesEnabled() does not change anything when you change
the layout, which is what you do with the show() and hide(). There are ways
to work around this, but you probably won't like it. I know that I don't, and
I have used different versions of these several times.
One trick is to encapsulate your changes in a QStackedWidget. In the
particular case, you would have a stack in each "slot" and when scrolling you
change all four - start at the end with the new widget, add this to the
stack, remove the widget previously located there, add that to the next
stack, and so on. If your widgets are identical height, this will work well.
If they are not identical height, you will get an ugly wobbly effect up or
down the stacks.
In that case, you can do something completely different: Have one big
QStackedWidget containing your current widget with all four slots in one page
and a QLabel on another. When you want to switch, you do a pixmap snapshot of
the current view, set that on the label, switch the stack to show the label,
remove the widget (you must do the remove first, or the stack will take up
more space from the layouts) and add the new widget, remove the label from
the stack. The removal of the label will force the stack to do it's new
layout handling in one go.
Another solution that is much cleaner, if it works in your particular case, is
to temporarily set a fixed size on your container widget and add a spacing to
the container at the point where you will be removing the widget. To do this,
you need to worry about avoiding the standard widget space between the
widgets and the spacer, because you will have to add the spacer while all the
current widgets are in there. With the spacer in place and your container
fixed, you can remove the old widget, add the new one, remove the spacer and
remove the fix on the layout. If this is the one you choose, I would probably
make another container around your current container that holds two empty
qwidgets to be used as spacers and your current container between them. Set
spacing and margin to 0 on this one and hide both spacers unless when needed
for the exchanging of the widgets.
There are other tricks you might want to try, but I would start with the
spacer version first, then a QStackedWidget approach, and resort to the
snapshot QLabel only when you're really really desperate. In all of the
possible solutions of this, you're going to have to be absolutely certain you
truly understand how the layout managing will work and be careful about
spaces between widgets.
I hope this helps,
Bo.
--
[ signature omitted ]
Message 3 in thread
Bo Thorsen a écrit :
> There are other tricks you might want to try, but I would start with
> the spacer version first, then a QStackedWidget approach, and resort
> to the snapshot QLabel only when you're really really desperate. In
> all of the possible solutions of this, you're going to have to be
> absolutely certain you truly understand how the layout managing will
> work and be careful about spaces between widgets.
>
> I hope this helps,
>
> Bo.
>
Dear Bo & others,
Thank you for all your solutions. I think they will help me at some
point when I encounter some other
kind of difficult issue. I could solve my problem in a simple but (a
bit) ugly way. I noticed that there
was flickering when showing a 5th widget first, and then hiding another
widget (the layout grows and
then recovers its initial size almost immediately). But there was no
flickering when I did the reverse
process (first hide, then show): the layout does not shrink. Therefore I
make sure that I always hide
a widget first before I show another, and it works. I just hope that it
will not produce some side
effects later.
Best regards,
Alex
--
[ signature omitted ]
Message 4 in thread
On Tue, 04 Dec 2007 16:16:02 +0100, Alexandre Beraud <aberaud@xxxxxxxxxxx>
wrote:
> I have a layout containing, say, 10 widgets. 4 are visible at a time,
> and I have buttons that allow to "scroll"
> inside the list of widgets. I hide() and show() the corresponding
> widgets. The problem is that at some point
> I show() a 5th widget just before hiding another, resulting in some
> annoying flickering. I tried to use
> setUpdatesEnabled() before and after the modifications but it does not
> change anything. Is there a way to
> handle this problem ? Any hint ?
Wouldn't simply disabling the layout just before you do the hide() and
show(), and enabling it again afterwards, solve this? (QLayout::enable())
- Eirik Aa.
--
[ signature omitted ]