0
votes

Parent widget doesn't respond to first mouse click after Modal QDialog closed, the QDialog is closed by calling done() in mousemoveevent() and this causes the mouse button is still being pressed after the dialog is closed, the second click onward will work as normal.

My finding so far:

  1. If done(int) is called in MouseReleaseeEvent(), everything works as expected

  2. It seems like the QDialog is lack of MouseButtonRelease event (which it's expecting after a MouseButtonPress event fired) due to the QDialog is already closed in the MouseMoveEvent and this messes up the mouse event of the parent widget.

My intention is to make a QDialog which can be closed by sliding, when It detects mouse pressed and moved to certain position, it will be closed.

It is much appreciated if everyone who encountered it before or who has any idea what's going on to give me some advice.

MANY THANKS.

Also, this is the first time I post a question here, if I missed any information that I suppose to provide, please let me know...

1
Do you call the parent mousemoveevent?fonZ
Maybe you could call the mouserelease event manually in the closeevent. That is probably a hack but will work if the rest fails.fonZ
Thanks Jon! I tried to manually call the mouserelease event but no luck. It seems like the QDialog insists to have a complete routine (mousepress + mouserelease) before it can release the control back to it's parent properly. My current workaround is to call the close event only after the user releases the mouse/touch and everything works fine. My curious is have anyone implemented the "iphone like slide to unlock" interface in Qt, and how was it done?Casey Lim

1 Answers

0
votes

This works perfectly, without any animations but those can be added. Basically what it does is looking for a difference in the x coordinate when the mouse started moving, if it is higher or lower than 2 (slide left or right) it will close the dialog.

int x;

void MyDialog::mousePressEvent(QMouseEvent * event) {
    x = event->globalPos().x();
}

void MyDialog::mouseReleaseEvent(QMouseEvent * event) {
    int diff = x - event->globalPos().x();
    qDebug(tr("released").arg(diff).toUtf8().constData());
    if (diff > 2 || diff < -2) QDialog::close();
}

I dont see any problem.