Added Dial Object to scene.To move object setting QGraphicsRectitem as a parent and resizing the widget through sizegrip. using lamda function to get widget geometry change and to resize parent QGraphicsRectItem . Dial Object i can resize upto some size after that i cant.Why its happening?
Here is Code
Dial.h
#include <QDial>
class Dial : public QDial
{
Q_OBJECT
public:
Dial(QWidget * parent = nullptr);
signals:
void sizeChanged();
protected:
void resizeEvent(QResizeEvent *event);
};
Dial.cpp
#include "dial.h"
Dial::Dial(QWidget *parent ) :
QDial(parent)
{
}
void Dial::resizeEvent(QResizeEvent *event)
{
QDial::resizeEvent(event);
emit sizeChanged();
}
mainWindow.cpp
QGraphicsView *view = new QGraphicsView();
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QGraphicsScene *scene = new QGraphicsScene();
scene->setBackgroundBrush(QBrush(Qt::cyan, Qt::SolidPattern));
view->setSceneRect(0,0,view->frameSize().width(),view->frameSize().height());
view->setScene(scene);
setCentralWidget(view);
auto *dial= new Dial(); // The widget // Dial subclass of QDial
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(10,10, 100, 100);
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
connect(dial, &Dial::sizeChanged, [dial, handle](){ handle->setRect(dial->geometry().adjusted(-10, -10, 10, 10));});