2 Attachment(s)
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?
Attachment 6503 Attachment 6504
Re: Drag and Drop with tabified dock widgets
I was already close. Here's the solution:
Code:
setAcceptDrops(true);
_tab_drag_index = -1;
_tab_drag_tab_bar = NULL;
_tab_drag_timer
= new QTimer(this);
_tab_drag_timer->setSingleShot(True);
connect(_tab_drag_timer, SIGNAL(timeout()); this, SLOT(_auto_switch_tab));
}
event.accept();
}
_tab_drag_timer.stop();
event.accept();
}
QTabBar * tabBar
= dynamic_cast<QTabBar
*>
(childAt
(event.
pos));
if (tabBar == NULL || tabBar->parent() != this) {
event->ignore();
return;
}
QPoint global_pos
= mapToGlobal
(event
->pos
());
QPoint widget_pos
= tabBar
->mapFromGlobal
(global_pos
);
int tab_index = tabBar->tabAt(widget_pos);
if (tab_index != _tab_drag_index && tabBar != _tab_drag_tab_bar) {
_tab_drag_timer->stop();
_tab_drag_index = tab_index;
_tab_drag_tab_bar = tabBar;
}
if (tab_index == -1) {
event->ignore();
return
}
event->accept();
}
void _auto_switch_tab() {
if (!_tab_drag_tab_bar || _tab_drag_index == -1)
return;
_tab_drag_tab_bar->setCurrentIndex(_tab_drag_index);
_tab_drag_tab_bar = NULL;
_tab_drag_index = -1;
}