c++ - Change QWidget Parent During Mouse Event -
i'm trying create detachable type style widget, in way chrome tabs detachable (class called tab). have working, except bug (maybe 50% of time), tab object never gets mouse release event, , stops getting mouse move events.
essentially, detaching scheme works allowing drags in mouse press/move/release functions, normal. mousemoveevent
checks total distance moved start, , if on amount, start "detaching" process. detaching process involves setting parent widget 0 (top level widget, undecorated window), tab object pretty much floating above everything, under mouse, , continues dragged along until released.
i ran through qevent
items beingness delivered, , found when issue occurs, qevent::mousemove items (and mouse events after this) beingness sent tabbar (the tab object's original parent). occurs straight after calling setparent(0)
on tab.
void tab::mousepressevent(*) { [set boolean, start positions, etc] } void tab::mousemoveevent(*) { [track updated position] if (positionchange > static_amount) detachtab(); } void tab::mousereleaseevent(*) { [return tab original position, , set parent tabbar] } void tab::detachtab() { qpoint mappedpos = maptoglobal(0, 0); setparent(0); //the loss of mousemove events occurs when returns. move(mappedpos); show(); raise(); }
here events tab object receives (first row qevent type, sec name)
[tab::detachtab() started] [setparent(0) started] qevent::hide qevent::leave qapp qevent::mousemove [ tabbar ] <-- tabbar soaking mouse events qevent::hidetoparent qevent::parentabouttochange qevent::parentchange [setparent(0) returned] ....
summed up: draggable qwidget loses qevent::mousemove , qevent::mousebuttonrelease events after having parent set 0.
any advice appreciated!
a bit tricky workaround. didn't test it, it's idea.
when mouse hovers draggable part of widget may create topmost widget (let's phone call shade) qt::framelesswindowhint
(and possible qt::wa_translucentbackground
). may manipulate shade apperance via reimplementing paintevent
. illustration - draw content of original widget, or draw transparent preview, etc.
then may resize shade during dragging, show user widget detached. not loose mouse capture.
when user release mouse - remember position of shade, destroy , detach+move original widget.
feel free ask, if want more details.
c++ qt qt5 qwidget
No comments:
Post a Comment