Greetings. I develop drag-and-drop tabs for an MDI application, like in Chrome or Visual Studio . For this, I have compiled the following conditions:
- If in
QTabBar> 1 tab, then when dragging a tab outside theQTabBarit becomes a window, usingsetParent(nullptr);and continues to move behind the mouse cursor until we release the left button. - If
QTabBar1 tab, then when dragging a tab, we simply move the window. - If, while dragging a window using the method described in
QTabBar2, we dragged a tab onto aQTabBar, the window becomes a tab inside thatQTabBar.
It should also be noted that there may be an unlimited number of windows and tabs. And cross-platform application.
I managed to implement the first 2 conditions, but I haven't been able to solve 3 days already. Question : How to determine that when dragging a window (as in QTabBar 2) we hit the QTabBar area? Or how to make the QTabBar to which we moved the tab to receive the event? What can you advise to implement 3 points?
The difficulty is that I cannot use the widgetAt(); method widgetAt(); because when dragging it will always return a pointer to the tab, and not to the widget under the window (the QTabBar I QTabBar ).
Study
In order to catch the mouse hover event in QTabBar , I tried such methods that, however, did not work:
setAttribute(Qt::WA_TransparentForMouseEvents, true);in order for the top window to let events through itself. It works only for widgets in one window.event->ignore();again, in order to skip the event. Acts similarly to the above.- The
QHoverEventclass for the widget to receive events, even if blocked by another. It does not fit, because only works in one window.
Manual search, as advised by @isnullxbh, of all areas (via QTabBar::rect()->contains(mouse->globalPos()) ) is also not quite suitable, since costly in resources and problems arise if windows with QTabBar'ами overlap.