View Full Version : Drag 'n drop Tab inside and outside the Main Application
mstegehu
16th July 2012, 21:54
With the help of QT Centre Movable Tabs Example (http://www.qtcentre.org/wiki/index.php?title=Movable_Tabs) I tried to create 'tear-off' tabs but it does not work. The functionality desired is the tabs drag 'n drop outside the application resulting in a new instance of that application. Examples are most Internet Browsers like Chrome/FireFox/IE etc.
What should I do after creating a DragEvent in the QTabBar::moveMouseEvent?
I guess while within the borders off the QMainWindow a DropEvent can be catched. But what if I drop outside the QMainWindow. How do I catch that event?
Does anyone have an example of this functionality?
Regards,
Marcel
mstegehu
18th July 2012, 15:48
I created a solution that does work but also has some hick-ups. Maybe somebody has an idea what might be wrong:
Requirements:
1. Tabs are (animated) movable (QTabBar::setMovable)
2. Tabs can be detached and attached by using the mouse and tear the tab off the tabbar.
So I implemented it and you can see the code I attached 8024.
I have a few problems with this code:
1. In the original application where I use the MHTabWidget and MHTabBar the tabbar does not seem to be updated after a detach.
1. I tear the tab with the title 'Tab 3'. The dialog is created for 'Tab 4'.
2. I am missing my widget but that will probably a simple mistake (removeTab and setParent might be a problem)
3. But the tabbar shows the wrong tabs and wrong selections.
See: 8022
4. After clicking on a tab in the tabbar it gets updated
5. And than I see both tab 3 and 4 are gone .
See: 8023
2. When I detach the last tab of the bar ('Tab 6'). It looks like index 3 removes index 4.
1. I get a QT error about a QList
Regards,
Marcel
mstegehu
23rd July 2012, 08:59
I solved the issues I had with the Detachable / Tear-Off Tabs and thought it might be nice to give you all the solution:
Here the files are: 8032
Solved issues:
1. TabBar update solved by turning off Moving while drag is initiated (Trick in TabBar::mouseMoveEvent)
2. Widget not visible after reparent: call setVisible or show. The funny thing is that the Attach does work without setVisible.
3. Wrong Tab: Called TabWidget for index / text after a reparent. Solved this. Also some interference due to movable tabs.
4. 5. 6. 7. All solved by turning off movable tabs.
Now I have two remaining features left:
1. In the drag I show a screen shot off the widget. It would be nice if the Tab is shown also in that screen shot.
2. It would be nice if a drag returns in the TabBar the Drag would stop and the move would continue.
Hope somebody is helped with this solution.
Regards,
Marcel
mstegehu
25th July 2012, 09:13
Hereby the example code.
8040
mstegehu
13th August 2012, 09:01
With a minor change in QDrag::setDargCursor it is possible to set the drag cursor for the ignore action.
QDrag setDragCursor allow change cursor for Qt::IgnoreAction (https://bugreports.qt-project.org/browse/QTBUG-26724)
Has someone an idea how to add a Tab to the pixmap of the drag?
code.yash
22nd June 2014, 21:30
from TabBar we can call
QRect rect = tabRect( currentIndex() );
QPixmap pixmap = grab(rect);
It will be tab's screenshot.
Your posted example is really nice. Thanks.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.