mardi 28 août 2018

Why Lamda function restricting widget enlarging?

when Drop event triggers adding Dial object to scene(QGraphicScene) dynamically through a QGraphicsProxyWidget.To move object setting QGraphicsRectitem as a parent and resizing the widget through sizegrip. when i create a object first time i can enlarge that upto some dimension, second time i can enlarge less than first one,third time less than second one .. so on its behaving randomly.Why its happening? Here is Code

 void GraphicsView::dropEvent(QDropEvent *event)
 {
   if(event->mimeData()->text() == "Dial")
   {
     auto *dial= new QDial();      // The widget
     auto *handle = new QGraphicsRectItem(QRect(event->pos().x(),event->pos().y(), 120, 120));    // Created to move and select on scene
     auto *proxy = new QGraphicsProxyWidget(handle); // Adding the widget through the proxy
     dial->setGeometry(event->pos().x()+10,event->pos().y()+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));});
   }
 }      

Here is the image out

Aucun commentaire:

Enregistrer un commentaire