简体   繁体   中英

Qt add Widget to GraphicsView?

Is there a way to draw Widgets on QGraphicsView instead of QGraphicsScene so that the widget stays in position when the scene is moved?

I want to create some dialogs that are dockable inside the workspace like this:

在此输入图像描述 http://www.thebandfrom.com/wp-content/uploads/photoshop-ui.png

You can use the addWidget function of QGraphicsScene , and then set the QGraphicsItem::ItemIgnoresTransformations flag to the added QGraphicsProxyWidget .

QGraphicsProxyWidget* proxyWidget = scene->addWidget(myWidget);
proxyWidget->setFlag(QGraphicsItem::ItemIgnoresTransformations);

You can add widgets onto the QGraphicsView directly by setting the QGraphicsView as their parent. You could also add a layout so that when the QGraphicsView is resized, your widgets arrange themselves appropriately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM