Replacing a child widget during a drag&drop
I'm writing an overlay for a custom widget, that should be displayed while dragging something on it. This overlay can contain information on what will happen if the object is dropped, or different drop zones. However, it seems that adding or removing a child widget (the overlay) during a drag causes a pair QDragLeaveEvent and QDragEnterEvent to be emitted, even though acceptDrops is false on the overlay widget.
Because I create the child on dragEnter and remove it on dragLeave, this causes a loop that causes the overlay to flicker, and I can't handle the drop correctly.
This issue only seems to happen on Mac OS (on Windows this works fine).
How should I work around this issue? Is it considered safe to change child widgets during these two events?
Thank you for your time
Since it's an overlay widget, did you set the Qt::WA_TransparentForMouseEvents flag ? That should make your widget "invisible" for move related events.
Hope it helps
Thank you! I can set it when the overlay appears while dragging, and this fixes my problem.
I had no idea there was a flag like this (or that "widget attributes":http://doc.qt.digia.com/qt/qwidget.html#setAttribute existed at all).
I think you can set it at construction time, so your widget is "transparent" from the start.
[quote author="SGaist" date="1360777331"]I think you can set it at construction time, so your widget is "transparent" from the start.[/quote]
Yes, indeed. But this overlay is sometimes constructed during a drag (then I don't want it to interfere with mouse events) and sometimes not (then it has to respond to clicks). I am setting the flag if appropriate in my constructor. Thank you again!
Ok, it seems my problem is not resolved after all...
When my widget gets a dragEnterEvent, it replaces the current overlay (a widget without WA_TransparentForMouseEvents) with another one (a widget with WA_TransparentForMouseEvents set). This works fine on Windows, but crashes (segmentation fault) on Mac OS (not even all the time...)
If WA_TransparentForMouseEvents was set on the previous widget (the one I'm replacing) it works even on Mac OS.
I don't understand what is going on.
@Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000100000042
0 QtCore 0x0000000109b7bb84 QCoreApplication::notifyInternal(QObject*, QEvent*) + 100
1 QtGui 0x000000010a7d29a0 -[QCocoaWindow draggingEntered:] + 992
2 QtGui 0x000000010a7d31eb -[QCocoaWindow draggingUpdated:] + 507
3 com.apple.AppKit 0x00007fff94a00bfc sendDraggingUpdate + 128
4 com.apple.AppKit 0x00007fff94a01d6f NSCoreDragTrackingProc + 2669
5 com.apple.HIServices 0x00007fff90015c6d DoTrackingMessage + 357
6 com.apple.HIServices 0x00007fff900156d2 SendTrackingMessage + 44
7 com.apple.HIServices 0x00007fff90018aa3 DragInApplication + 264
8 com.apple.HIServices 0x00007fff90018f0a CoreDragStartDragging + 517
9 com.apple.AppKit 0x00007fff94a006c0 -[NSCoreDragManager _dragUntilMouseUp:accepted:] + 885
10 com.apple.AppKit 0x00007fff949ffd8c -[NSCoreDragManager dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:] + 1455
11 com.apple.AppKit 0x00007fff94cf8cc6 -[NSWindow(NSDrag) dragImage:at:offset:event:pasteboard:source:slideBack:] + 132
12 QtGui 0x000000010a7cf132 QDragManager::drag(QDrag*) + 818
13 QtGui 0x000000010a83e067 QDrag::start(QFlagsQt::DropAction) + 87