Widget transparent to mouse events, except drag and drop, sometimes

  • I have a parent widget, and I have an "overlay" widget which is the last child widget of the parent. I want to have the overlay be able to draw stuff on top of the parent, and respond to some drag and drop events. So far, I have drawing the overlay working, and I am currently doing "setAttribute(Qt::WA_TransparentForMouseEvents);" so normal mouse events are being based to the underlying widgets. But, I want to allow the overlay to respond to some drags. Doing "setAcceptDrops(true);" doesn't seem to have any effect after I set it to be transparent. for events

    So, how can I make a widget that is transparent to "normal" events, but still responds to drag and drop?

  • Lifetime Qt Champion


    How are you doing the drag & drop ?

  • After quite a bit of tinkering, I have changed the way I was doing drag and drop, and gotten it to work by not having the overlay widget responsible for anything related to the drag and drop. Instead, the overlay widget is invisible by default, and is transparent to all mouse events.

    The parent widget, however, is responsible for responding to the dragEnter/dragMove/drop events. Whenever the parent gets an enter event, it basically does overlay->showOverlay() and triggers an overlay->update() on every parent::dragMove. The result is that the overlay can show the helpful information that I want in response to drags.

    I'm not sure if this split responsibility model is the most efficient way to do it, but after a few days of tinkering, it certainly seems to work better than anything else I tried.

  • Lifetime Qt Champion

    It sure is way cleaner. Since it looks that this overlay widget responsibility is only to show additional information, then this is the correct design.

Log in to reply