0

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));});
Sagar A W
  • 338
  • 1
  • 12
  • dial is a QDial or a Dial. I point it out to you because with the following code: `auto *dial= new QDial();` you are creating a QDial that does not have the sizeChanged signal and therefore the following line: `connect(dial, &Dial::sizeChanged, ...)` should throw you an error. please improve your code and provide a [mcve] – eyllanesc Aug 29 '18 at 05:18
  • provide a decent [mcve] – eyllanesc Aug 29 '18 at 05:59
  • I want a [mcve] to be able to analyze where the error is, have you read the link? Do you understand what an MCVE is? – eyllanesc Aug 29 '18 at 06:02
  • @eyllanesc MCVE added..Please go through this now. – Sagar A W Aug 29 '18 at 06:44
  • 1
    the problem is not the lambda method, please edit your title to not distract us at that point, the problem is that the proxy that can not extend beyond the sceneRect, you have to understand that the sceneRect is not the same as the viewport, even I am investigating a possible solution. – eyllanesc Aug 29 '18 at 07:51
  • @Sagar, why did you post that twice, instead of updating your [other question](https://stackoverflow.com/q/52060862/5366641)? – scopchanov Aug 29 '18 at 09:53
  • 1
    @eyllanesc, for some reason Sagar decided to add the details about the question as a new question. This one should be deleted, I think. – scopchanov Aug 29 '18 at 10:13
  • 1
    @scopchanov If you check the history you will see that initially it was the same question, and following my observations the improvement to have the current status, any of the questions must be closed, so I have marked it as a duplicate and I have reported it so that a user with gold medal closing. – eyllanesc Aug 29 '18 at 10:15
  • @eyllanesc, I see. – scopchanov Aug 29 '18 at 10:16

0 Answers0