PDA

View Full Version : QTabWidget Drag&Drop problem - dropping items to tabs



Fenix Voltres
19th February 2010, 23:29
Hey, I've got my own subclass of QTabWidget (using my own reimplementation of QTabBar) - each tab has QListWidget as its page - and I want to enable D&D between the tabs, but I encountered some problems:

1) I want to be able to drag an item from QListWidget and drop it on a tab, what would add that item to that tab's QListWidget. In order to do that I tried something like this in MyQTabWidget:


void MyQTabWidget::dropEvent(QDropEvent *event)
{
int index = tabs->tabAt(tabs->mapFromParent(event->pos()));
if (index == -1)
event->ignore(); // don't know if it's right way to ignore that event - item is removed from previous tab :/
else
{
lw = currentWidget()->findChild<QListWidget *>("lista");
ev = new QDropEvent(*event);
qApp->postEvent(lw, ev);
}
}

but, as you can guess, it doesn't work properly. Of corse every QListWidget has objectName "lista" and set all of needed properties (D&D WORKS when I drop item directly to the QListWidget). Suppose I make some terrible logic mistakes since I'm new to Qt D&D system :)

2) When I'm receiving dragEnterEvent, I check if any tabRect of tabs contains event->pos(). If it does, I set it as a current tab. Problem is, when I receive dragEnterEvent on one tab then I move cursor to another - now I don't receive second dragEnterEvent, since cursor remains in TabBar... I skipped this problem by using dragMoveEvent - but to do that I had to call event->accept() in dragEnterEvent - and now when I place cursor firstly on tab, then move to area right to last tab I'm still able to drop the item, what should be forbidden... Is any way to change possibility of dropping when QDropEvent was accepted? Or "unaccept" it? And again, maybe I misunderstand Qt D&D system, but... hopefully you can help me :)

Fenix Voltres
27th February 2010, 11:39
BUMP
Anyone?