PDA

View Full Version : Different behavior on Windows & OS X, when a QGraphicsItem is dragged out of QGraphic



royt
1st July 2012, 17:15
I noticed that on Windows and Mac OS X 10.6, when dragging a QGraphicsItem out of the current QGraphicsView, but still in the QGraphicsScene, the code flow is not same. And I think there may be something wrong on OS X. In file "QGraphicsScene.cpp", there is a function:

void QGraphicsScenePrivate::sendMouseEvent(QGraphicsSce neMouseEvent *mouseEvent)
{
if (mouseEvent->button() == 0 && mouseEvent->buttons() == 0 && lastMouseGrabberItemHasImplicitMouseGrab) {
// ### This is a temporary fix for until we get proper mouse
// grab events.
clearMouseGrabber();
return;
}
...
}

Just set a breakpoint there, on Mac OS, the if condition is true, so sendMouseEvent will return, and following code for event handling won't be executed, that will make something wrong. I think function button() should return LeftButton, that is the button pressed before dragging, but NoButton is returned. If the QGraphicsItem not dragged out of the QGraphicsView, all things are right.

I think maybe it's a Qt bug, who can tell me when the value for button is changed after the QGraphicsSceneMouseEvent is made (where is the related line in source code)? Thanks!

royt
2nd July 2012, 04:54
I have investigate into this issue, and I found following lines in function "qt_mac_handleMouseEvent", file "qt_cocoa_helpers_mac.mm" :

Qt::MouseButtons buttons = 0;
{
UInt32 mac_buttons;
if (GetEventParameter(carbonEvent, kEventParamMouseChord, typeUInt32, 0,
sizeof(mac_buttons), 0, &mac_buttons) == noErr)
buttons = qt_mac_get_buttons(mac_buttons);
}

When the QGraphicsItem is dragged out of the view and then dragged back, the value of mac_buttons is 0 (NoButton), however the LeftButton is keeping pressed. So I guess the here is the issue. But I don't know how to deal with it.