Results 1 to 2 of 2

Thread: Drag and Drop with tabified dock widgets

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    88
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Wiki edits
    1

    Default Drag and Drop with tabified dock widgets

    I have a QMainWindow with a bunch of dock widgets. Like most of you, I can drag something from one of the dock widgets and drop it on my desktop. I can also drag something from one of the dock widgets to another dock widget. Pretty straight forward. (Something like this example http://www.qtcentre.org/wiki/index.p...ed_Main_Window)

    The hard part that I can't find out is, I want to drag something from one dock widget to a tabified dock widget. For example, imagine you have two tabified dock widgets, one on top of the other, how can you drag something from the top dock widget to the obscured dock widget? Obviously, the only thing you can drag it to is the tab bar, but I'm finding it exceedingly hard to detect a drag event ontop of the tab bar.

    Anyone cracked this nut yet?

    drag-1.png drag-2.png
    Last edited by chezifresh; 1st June 2011 at 23:48.

  2. #2
    Join Date
    Jun 2008
    Posts
    88
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Wiki edits
    1

    Default Re: Drag and Drop with tabified dock widgets

    I was already close. Here's the solution:

    Qt Code:
    1. MyMainWindow(QWidget * parent) : QMainWindow(parent) {
    2. setAcceptDrops(true);
    3. _tab_drag_index = -1;
    4. _tab_drag_tab_bar = NULL;
    5. _tab_drag_timer = new QTimer(this);
    6. _tab_drag_timer->setSingleShot(True);
    7. connect(_tab_drag_timer, SIGNAL(timeout()); this, SLOT(_auto_switch_tab));
    8. }
    9.  
    10. void dragEnterEvent(QDragEnterEvent * event) {
    11. event.accept();
    12. }
    13.  
    14. void dragLeaveEvent(QDragLeaveEvent * event) {
    15. _tab_drag_timer.stop();
    16. event.accept();
    17. }
    18.  
    19. void dragMoveEvent(QDragMoveEvent * event) {
    20. QTabBar * tabBar = dynamic_cast<QTabBar *>(childAt(event.pos));
    21. if (tabBar == NULL || tabBar->parent() != this) {
    22. event->ignore();
    23. return;
    24. }
    25.  
    26. QPoint global_pos = mapToGlobal(event->pos());
    27. QPoint widget_pos = tabBar->mapFromGlobal(global_pos);
    28.  
    29. int tab_index = tabBar->tabAt(widget_pos);
    30. if (tab_index != _tab_drag_index && tabBar != _tab_drag_tab_bar) {
    31. _tab_drag_timer->stop();
    32. _tab_drag_index = tab_index;
    33. _tab_drag_tab_bar = tabBar;
    34. _tab_drag_timer->start(QApplication.startDragTime());
    35. }
    36. if (tab_index == -1) {
    37. event->ignore();
    38. return
    39. }
    40. event->accept();
    41.  
    42. }
    43.  
    44. void _auto_switch_tab() {
    45. if (!_tab_drag_tab_bar || _tab_drag_index == -1)
    46. return;
    47. _tab_drag_tab_bar->setCurrentIndex(_tab_drag_index);
    48. _tab_drag_tab_bar = NULL;
    49. _tab_drag_index = -1;
    50. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by chezifresh; 2nd June 2011 at 22:57.

Similar Threads

  1. Qt 4.4 with Ecplise: can't drag and drop widgets?
    By squish in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2012, 20:29
  2. drag and drop in list widgets
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 28th May 2011, 08:51
  3. move/drag tabified QDockWidget's togeter
    By qtui in forum Qt Programming
    Replies: 0
    Last Post: 14th February 2011, 00:01
  4. hide tab within a tabified dock widget
    By navid in forum Qt Programming
    Replies: 9
    Last Post: 7th July 2010, 17:12
  5. hideEvent not propagated to tabified dock widgets
    By spud in forum Qt Programming
    Replies: 2
    Last Post: 4th October 2007, 09:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.