0

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...

Casey Lim
  • 1
  • 2
  • Do you call the parent mousemoveevent? – fonZ Oct 16 '12 at 16:47
  • Maybe you could call the mouserelease event manually in the closeevent. That is probably a hack but will work if the rest fails. – fonZ Oct 16 '12 at 16:50
  • 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 Oct 22 '12 at 02:21

1 Answers1

0

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.

fonZ
  • 2,428
  • 4
  • 21
  • 40
  • Thanks again for spending time on this. As what I said, calling the close() in mouseReleaseEvent has no problem at all. Do you mind trying to call the close() in mouseMoveEvent, probably you could simulate the same problem. – Casey Lim Oct 23 '12 at 06:09
  • I dont think you want to trigger close on click but i tested it out, i call close when mousePressEvent is triggered and everything works fine. The dialog closes as expected. – fonZ Oct 23 '12 at 10:47