[Qt-interest] Using QGraphicsLayouts inside QGraphicsWidgets
Sean Harmer
sean.harmer at maps-technology.com
Mon Jun 27 11:06:20 CEST 2011
Hi,
On Monday 27 June 2011 11:00:33 Schimkowitsch Robert wrote:
> I would like to create a QGraphicsWidget (something like a toolbar),
> that uses a QGraphicsLinearLayout inside, to manage the child
> GraphicsWidgets.
>
> My new GraphicsWidgets (let's call it ButtonBar) derives from
> QGraphicsWidget, and has a QGraphicsLinearLayout as a member.
OK.
> I have methods to add and remove items from the ButtonBar, and I
> basically expose the LinearLayout's SizeHint as the ButtonBar's SizeHint
> (so any outside layout will know how much room all my buttons need).
That should not be necessary. The QGW and QGL items should do that for you
with no code on your part. Just setting the layout is enough to do this.
> However, I have stumbled accross one problem I don't see a clean
> solution to:
> How will I realize when my LinearLayout needs to change it's size hint
> (e.g. because one of the buttons changed in size), so I can call
> updateGeometry and have my parent layout update?
> It's all very well when a button is added and removed - I can always
> call updateGeometry then. But what if a button changes in size for some
> other reason? How will I know?
>
> Any ideas how to solve that?
Any time one of your custom buttons changes it's size it should call
QGraphicsWidget::updateGeometry(). This will take care of propagating the
change in size hints up the widget/layout hierarchy.
At present this can take several iterations of the event loop due to a bug in
QGV (http://bugreports.qt.nokia.com/browse/QTBUG-17244). The fix for this is
coming in Qt 4.8.0 (and 4.7.4 if we get that release). The fix is opt-in
though and you'll need to call:
QGraphicsLayout::setInstantInvalidatePropagation(true);
to make it happen in a single pass.
Cheers,
Sean
More information about the Qt-interest-old
mailing list