2

i have implemented the mousePress, mouseMove and mouseRelase in the QGraphicsView and i have added a QGraphicsWidget and a QGraphicsLayoutItem in it and added to the view.

now inside the graphicsLayoutitem i have implemented

void ParentItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    m_mousePressed = true;
    QGraphicsObject::mousePressEvent(event);
}

void ParentItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (!(event->buttons() & Qt::LeftButton))
    {
        QGraphicsObject::mouseMoveEvent(event);
        return;
    }
    if( this->boundingRect().contains(event->pos()) && (m_mousePressed))
    {
        QGraphicsObject::mouseMoveEvent(event);

        QDrag *drag = new QDrag(this);
        QMimeData *mimeData = new QMimeData;




        // mime stuff
        mimeData->setText("Parent");


        drag->setPixmap(m_currentImage.scaled(30,30));
        drag->setHotSpot(QPoint(15, 20));

        drag->setMimeData(mimeData);



        // start drag
            drag->start(Qt::CopyAction | Qt::MoveAction);
}

so when i mouseMove in parentitem the Drag is been exec succesfully and when i drop the item in scene , the graphicsView is not getting the mouseRelease event. The graphicsview mouseRelease event is not been called when i drop it on scene.

this is how i handle the drop in scene

void HandlerScene::dropEvent ( QGraphicsSceneDragDropEvent * event )
{
if (event->mimeData()->hasText()){

        if(event->mimeData()->text() == "Parent")
{
   //My code
}
 event->acceptProposedAction();
}

The sample code i have uploaded in the http://filesave.me/file/53135/DropItem-zip.html

You can Drag and drop on the item and it will create a new item. It works fine but when i give setFocus(Qt::mouseFocusReason) to the item the actual problem starts.

user on double clicking on the Text of the item i added a Qgraphicstextitem on top of it. when the textitem lost focus im deleting it.

In normal condition without double clicking on the item text,the drag and drop is working fine.

but when i add the QGraphicsTextItem on the top of the item and set the focus as setFocus(Qt::mouseFocusReason) and if i again drag the item the QGraphicsView mouseMove event is keep on calling.

Wagmare
  • 1,354
  • 1
  • 24
  • 58
  • have you setAcceptDrops(true) ? – nayana Mar 25 '15 at 08:01
  • Yes. the drop is working fine but the view (Graphicsview) stops receiving the event (mouse Relese Event) – Wagmare Mar 25 '15 at 08:25
  • Maybe [this](http://stackoverflow.com/a/2163465/3876138) will help – nayana Mar 25 '15 at 08:52
  • I have attached my code link . you can add more item by drag and droping on the item. double click on the item will show an editable text item. so if you edit and lost focus , text item will be deleted. now you drag and drop the item and you can see the mouseMove of QGraphicsview will be called. – Wagmare Mar 25 '15 at 09:24
  • It's very likely that this is a Qt bug. If you can minimize the case, you should submit a bug report. `QDrag::exec()` is a semi-broken hack anyway, I wouldn't be surprised if it had this problem... – Kuba hasn't forgotten Monica Mar 26 '15 at 19:52

0 Answers0