PDA

View Full Version : QWidgets inside QGraphicsWidget [parent issue]



jovin
23rd April 2012, 17:17
Hello,

I don't know if the problem is due to bad design or anything...
However, I have a subclass of QGraphicsWidget. Now I want to add some widgets to the subclass (here: QProgressBar)
and it works to some extend; they appear but aren't in my QGraphicsScene which my subclass is part of (via addItem()) .

I came to the conclusion that the problem has to be that the widgets inside my subclass don't have a parent.
Now I could call widget_inside_subclass.setParent(this), but they only accept QObjects* and my subclass is a QGraphicsWidget.

Is there a way to "force" them to be my subclass' child's?
Even better solutions are also welcome.

Thanks.

- jovin

norobro
24th April 2012, 04:01
. . . but they only accept QObjects* and my subclass is a QGraphicsWidget.
I don't understand the problem since: QObject <- QGraphicsObject <- QGraphicsWidget

Anyway, try putting your widgets in the layout of the QGraphicsWidget. There is a good example in the docs, here (http://doc-snapshot.qt-project.org/4.8/qgraphicslinearlayout.html#details).

Spitfire
25th April 2012, 12:48
Also take a look at QGraphicsProxyWidget (http://qt-project.org/doc/qt-4.8/qgraphicsproxywidget.html).