How exactly can I subclass QGraphicsLayoutItem?
I write a class that subclass QGraphicsLayoutItem and reimplement sizeHint and setGeometry but when I add my custom item to linear or grid layout. It does not shown?
What is missing?
Printable View
How exactly can I subclass QGraphicsLayoutItem?
I write a class that subclass QGraphicsLayoutItem and reimplement sizeHint and setGeometry but when I add my custom item to linear or grid layout. It does not shown?
What is missing?
QGraphicsItem is not a QWidget; it's meant to be displayed when it is placed into a QGraphicsScene which is then viewed with a QGraphicsView. It won't show up in a QLayout. In fact, I'm surprised you're able to add it in the first place.
A QGraphicsView descends from QWidget, and can be added to a QLayout.
I think you got me wrong. Cause there are existing layouts for QGraphicsView.
Look at these QGraphicsLinearLayout, QGraphicsGridLayout
In your original post, you were talking about a QGraphicsItem, not a QGraphicsView.
Maybe you could post a short example that demonstrates the problem?
Here my trial.
Code:
//compositeitem.h { ~CompositeItem(); }; //compositeitem.cpp { QGraphicsWidget *child; foreach(child,children) { addToGroup(child); } } CompositeItem::~CompositeItem() { } { ... } { QGraphicsLayoutItem::setGeometry(rect); } //mainwindow.cpp ui.graphicsView->setScene(scene); QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; CompositeItem * ci = new CompositeItem(...); layout->addItem(ci); QGraphicsWidget *container = new QGraphicsWidget; container->setLayout(layout); scene->addItem(container);
Here i do not see my compositeitem drawing on scene.
Did you solve your problem?
What happens if you add your CompositeItem directly to the scene?
And what is it you expect to see? I don't see any paint() routine or other functions that will cause anything to be displayed.
@GuL I don't solve my problem with this approach. But I write a custom composite item class that acts like a QGraphicsItemGroup, also can be added inside QGraphicsLayout.
@SixDegrees if I add my composite item directly to scene I see empty scene. There is no paint because I expect to see child items paints themselves.