Organize/Align multiple QGraphicsItems in a Layout? QGraphicsScene
Unsolved
General and Desktop
-
I know that somehow its needed to create a QGraphicsLinearLayout and inherit with my QGraphicsItem subclass from QGraphicsLayoutItem too. But somehow it doesn't looks like there is a layout created at all. I still can freely move my graphicsitems in the scene even when beeing added to the layout:
CustomGraphicsScene::CustomGraphicsScene(QObject *parent) : QGraphicsScene(parent) { // Create a layout and a widget to hold the items layout = new QGraphicsLinearLayout(Qt::Vertical); QGraphicsWidget *widget = new QGraphicsWidget; widget->setLayout(layout); addItem(widget); } void CustomGraphicsScene::dropEvent(QGraphicsSceneDragDropEvent *event) { if(event->mimeData()->property("Key").canConvert(QMetaType(QMetaType::Int))){ int key = event->mimeData()->property("Key").toInt(); switch(key){ case 10: { clearSelection(); ResizablePixmapItem * pixItem = new ResizablePixmapItem(QPixmap(":/resource/quick.png")); pixItem->setRect(0,0,100,100); pixItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsScenePositionChanges); addItem(pixItem); pixItem->setPos(event->scenePos() - QPointF(pixItem->boundingRect().width()/2, pixItem->boundingRect().height()/2)); pixItem->setSelected(true); layout->addItem(pixItem); //Erhöht den Counter für jedes gedroppete Item SceneItemCounter++; pixItem->setSceneID(SceneItemCounter); qDebug() << "SceneID: " << pixItem->getSceneID(); emit SendNewItemWasAddedtoScene(pixItem); emit SendItemsInSceneSelected(); } break;
Does anyone know how to do it properly? My goal is to control the aligment and position of all qgraphicsitems within the layout.
-
Have you checked the
QGraphicsLayout
example already?