Hang observed at drag->exec() when a qwidget is dragged after a QMessageBox error message has popped up.



  • Hi I'm working on an application for dragging and dropping of qwidgets.The drag and drop is working fine.I also have some QMessageBox poping up when position of qwidget dropped in improper locations.When I drop the widget in an improper location I get proper error messages in the form of QMessageBoxes,but after getting the pop ups If I drag the qwidget I'm observing a hang at drag->exec().Below is my code for dragging
    void Base::mouseMoveEvent (QMouseEvent *event)
    {
    if (event->buttons() & Qt::LeftButton)
    {
    {
    if (item)
    {
    QMimeData *mimeData = new QMimeData;
    mimeData->setText ("X");
    quintptr address = (quintptr)item;
    QByteArray b (QString::number (address).toLatin1());
    mimeData->setData (QStringLiteral ("image/x-puzzle-piece"), b);
    QDrag *drag = new QDrag (this);
    drag->setMimeData (mimeData);
    //Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
    drag->exec();
    //setCursor(Qt::OpenHandCursor);
    //drag->setPixmap(QPixmap(":/images/person.png"));
    //if (drag->exec (Qt::MoveAction) == Qt::MoveAction)
    //{ /delete item;/ }

        update();
    }
        }
    }
    
    QWidget::mouseMoveEvent (event);
    

    }

    This is my code for showing popups if the widget is dropped in improper location
    QMessageBox msg;
    msg.critical (0, "Error", errorMessage);
    msg.show();

    When I try to drag widget after the error message has come and "ok" is clicked It hangs at drag->exec().Please suggest


  • Lifetime Qt Champion

    Hi,

    Why not just disallow dropping on improper location ?



  • @SGaist
    Hi,
    Thanks for the reply.

    I have different conditions for Improper Location's.Basically the Improper locations are dynamic(depend on the locations of other QWidgets).The application has to clearly tell the user why the QWidget shouldn't be dropped in that location.So I tell the user through QMessageBox error popups.I couldn't find any alternative for QMessageBox.Please suggest If any.My issue is similar to this post and this .The drag->exec() is not getting returned.
    I'm working on Linux platform.


  • Lifetime Qt Champion

    How do you currently define that it's not allowed to drop ?



  • Hi @SGaist

    void Base::dropEvent (QDropEvent *event)
    {
    Base *source =
    qobject_cast<Base *> (event->source());

    if (source && source != this)
    {
       drop...
    }
    

    }


  • Lifetime Qt Champion

    See the dropping part of the Drag And Drop chapter of Qt's documentation. You should simply refuse the action in dragEnterEvent.


Log in to reply