我通过 QGraphicsProxyWidget 向图形场景 (QGraphicScene) 添加了一个小部件。为移动和选择小部件添加了 QGraphicsRectItem 句柄。要调整小部件的大小,请将 QSizegrip 添加到小部件。但是,当我调整小部件的大小超过 QGraphicsRect 项目时,右和下边缘落后。如何克服这个问题? 当我调整小部件图形矩形项目的大小时,应该调整大小,反之亦然。这个怎么做?欢迎任何其他想法。这是代码
auto *dial= new QDial(); // The widget
auto *handle = new QGraphicsRectItem(QRect(0, 0, 120, 120)); // Created to move and select on scene
auto *proxy = new QGraphicsProxyWidget(handle); // Adding the widget through the proxy
dial->setGeometry(0, 0, 100, 100);
dial->move(10, 10);
proxy->setWidget(dial);
QSizeGrip * sizeGrip = new QSizeGrip(dial);
QHBoxLayout *layout = new QHBoxLayout(dial);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(sizeGrip, 0, Qt::AlignRight | Qt::AlignBottom);
handle->setPen(QPen(Qt::transparent));
handle->setBrush(Qt::gray);
handle->setFlags(QGraphicsItem::ItemIsMovable |
QGraphicsItem::ItemIsSelectable);
Scene->addItem(handle); // adding to scene