PDA

View Full Version : Why QFrame does not resize on QgraphicsScene?



Manuka
4th April 2019, 15:49
Hi,

I have a QGraphicsScene to which I would like to add a QFrame. I'm doing so by calling the addWidget function of the QgraphicsScene class.
On the created QFrame I've added a grid layout which contains QGraphicsWidget classes.

Why the QFrame always keeps its size? If I have a small number of elements in the layout it fits well inside the QFrame but
as soon as I add too much elements the widgets go outside of the boundaries of the QFrame. (I can stell see them because the QGraphicsView scrolls but outside of the frame)

Actually my goal is the having a border around my grid layout.

Do you have any ideas?

Thanks

anda_skoa
5th April 2019, 09:32
That sounds like a broken approach, so maybe it is better if you describe what your goals are.

If you add a container widget like a QFrame you would add widgets to it, not graphic items. A container widgets knows nothing about graphics items, it only deals with child widgets.

Cheers,
_

Manuka
5th April 2019, 14:00
Thank you for your response.

I have a QGraphicsGridLayout with objects classes inheriting from QGraphicsWidget. My goal is to have a rectangle as a border around my QGraphicsGridLayout

Thanks!

Added after 51 minutes:

I thought another solution may be to inherit from QGraphicsWidget. Then set my grid layout on. Finally to override the paint function by calling the base class paint function QGraphicsWidget::paint() and then drawing a rectangle defined by the bounding rect.

anda_skoa
6th April 2019, 10:29
then drawing a rectangle defined by the bounding rect.

Or use a QGraphicsRectItem

Cheers,
_