PDA

View Full Version : Adding widgets to a QGraphicsView's margins



nmather
7th April 2007, 14:55
Hi,

With a QGraphicsView I can set the margins of the viewport with setViewportMargins (inherited from QAbstractScrollArea), but I am then unsure how to actually place widgets in those margins.

I tried both:


viewport()->layout()->addWidget( myWidget );

and


layout()->addWidget( myWidget );

But each case results in a seg fault, which I think means the layout in both cases hasn't yet been instantiated. However I would have thought the QGraphicsView must have a layout already, in which the viewport is placed, and the viewport must have a layout for which the margins get set?

Any tips on how to add widgets into the margins is greatly appreciated :)

Neil

marcel
7th April 2007, 15:10
You must not use the layout. You just position the widgets in the available left ant top areas.
To position the widgets you can use move().


Regards,
Marcel.

nmather
7th April 2007, 16:52
Thanks Marcel! I got it to work now. My problem was, for the widgets I was trying to put in the margins I wasn't properly passing the GraphicsView to them to be their parent -- the parent was just being set to 0, so of course nothing showed up!