Results 1 to 2 of 2

Thread: QTabWidget Drag&Drop problem - dropping items to tabs

  1. #1
    Join Date
    Jun 2009
    Location
    Kraków, Poland
    Posts
    23
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default QTabWidget Drag&Drop problem - dropping items to tabs

    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:
    Qt Code:
    1. void MyQTabWidget::dropEvent(QDropEvent *event)
    2. {
    3. int index = tabs->tabAt(tabs->mapFromParent(event->pos()));
    4. if (index == -1)
    5. event->ignore(); // don't know if it's right way to ignore that event - item is removed from previous tab :/
    6. else
    7. {
    8. lw = currentWidget()->findChild<QListWidget *>("lista");
    9. ev = new QDropEvent(*event);
    10. qApp->postEvent(lw, ev);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jun 2009
    Location
    Kraków, Poland
    Posts
    23
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QTabWidget Drag&Drop problem - dropping items to tabs

    BUMP
    Anyone?

Similar Threads

  1. Drag and Drop in QGraphicsScene misses items
    By enno in forum Qt Programming
    Replies: 2
    Last Post: 30th August 2009, 15:17
  2. QTabWidget drag and drop
    By ComaWhite in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2009, 13:03
  3. Drag and Drop a widget in and out QTabWidget
    By smarinr in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2008, 19:10
  4. Catch drag and drop items
    By nina1983 in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2008, 17:24
  5. Drag & drop items on the same QTreeView
    By wind in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2006, 14:29

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.