Results 1 to 17 of 17

Thread: Drag and Drop problem

  1. #1
    Join Date
    Nov 2006
    Posts
    15

    Question Drag and Drop problem

    Dear fellows,

    i've looked over the forum first and didn' find any possible matching case. I'm trying to do drag and drop over a table view header. i've sub classed the tableview and the headers to implement their dragenterevent and dropevent. Also my model implements minmetype(). but draging is disabled over the header. i donno y, and i've debugged alot. any body got any idea !!!!!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop problem

    Did you set acceptDrops property of the headerview to true? Did you implement mimeData() for your model (provided you want to drag items from the model)?

  3. #3
    Join Date
    Nov 2006
    Posts
    15

    Default Re: Drag and Drop problem

    yes all this stuff done, although my intention is to drop color item from another widget to the header of the tableview to color the columns.
    Last edited by ScoOteR; 19th December 2006 at 14:21.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop problem

    Does the headerview receive dragenter and drop events? You can check that by installing an event filter on the header view.

  5. #5
    Join Date
    Nov 2006
    Posts
    15

    Default Re: Drag and Drop problem

    I've debugged it the header receives the dragenters event but it doesn't enter the drop event as the dropping is disabled as I've mentioned before. and yes i accept the drop action in the drag enters event.

  6. #6
    Join Date
    Nov 2006
    Posts
    15

    Default Re: Drag and Drop problem

    I've tried something else. I've made a simple model which holds some static data and made another widget for it the drop was enabled over this one. Even though both have the same custom table view and custom header and both models implements mimeType. So, what do u think made it work with one model and not the other !!!!!!!!!!!!!!!!!!!!!1

  7. #7
    Join Date
    Nov 2006
    Posts
    15

    Default Re: Drag and Drop problem

    actually I've a new surprise for u all. On debugging I found that it stops @ the break point in the mimeType of my temp small model. and i doesn't in the other model I've been working with for a while. So, I'd really appreciate if any body told me what the heck on earth could make what's happening here make sense !!!!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop problem

    How did you enable drops for the header? Can you show the actual function call? Or maybe even a minimal compilable example?

  9. #9
    Join Date
    Nov 2006
    Posts
    15

    Default Re: Drag and Drop problem

    i think u didn't see my last post but any way here's the snippets u asked for

    Qt Code:
    1. CHeader::CHeader(QWidget *parent)
    2. : QHeaderView(Qt::Horizontal,parent)
    3. {
    4. ui.setupUi(this);
    5. setAcceptDrops(true);
    6. setDropIndicatorShown(true);
    7. m_table = (CMyTable*)parent;
    8. }
    To copy to clipboard, switch view to plain text mode 

    and here i associate this header to my custom table view
    Qt Code:
    1. CCustomColumnTableView::CCustomColumnTableView(QWidget *parent)
    2. : QTableView(parent)
    3. {
    4. CHeader * temp = new CHeader(this);
    5. setHorizontalHeader(temp);
    6. .
    7. .
    8. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop problem

    What about dragEnter and drop events?

  11. #11
    Join Date
    Nov 2006
    Posts
    15

    Default Re: Drag and Drop problem

    Qt Code:
    1. void CHeader::dragEnterEvent(QDragEnterEvent * event)
    2. {
    3. if (event->mimeData()->hasFormat("application/x-color"))
    4. event->acceptProposedAction();
    5. }
    6.  
    7. void CHeader::dropEvent(QDropEvent * event)
    8. {
    9. m_table->dropEvent(event);
    10. }
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop problem

    What happens if you drag over the header? Insert a debug statement and see if the handler gets triggered. It might be possible that the event is intercepted by the view in an event filter. If so, you have to either handle that event elsewhere or install another event filter to catch that event before the other filter gets it.

  13. #13
    Join Date
    Nov 2006
    Posts
    15

    Default Re: Drag and Drop problem

    Re: Drag and Drop problem
    I've tried something else. I've made a simple model which holds some static data and made another widget for it the drop was enabled over this one. Even though both have the same custom table view and custom header and both models implements mimeType. So, what do u think made it work with one model and not the other !!!!!!!!!!!!!!!!!!!!!1

    Re: Drag and Drop problem
    actually I've a new surprise for u all. On debugging I found that it stops @ the break point in the mimeType of my temp small model. and i doesn't in the other model I've been working with for a while. So, I'd really appreciate if any body told me what the heck on earth could make what's happening here make sense !!!!

    sorry but i think u've missed those to comments which I've posted early. So, I don't think it's related to the header or the table as those controls were common in the 2 previous cases!!!
    I'm a bit confused as I'm finding all what's going is making no sense

    and thanks a lot I really appreciate your interest.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop problem

    Quote Originally Posted by ScoOteR View Post
    Re: Drag and Drop problem
    I've tried something else. I've made a simple model which holds some static data and made another widget for it the drop was enabled over this one. Even though both have the same custom table view and custom header and both models implements mimeType. So, what do u think made it work with one model and not the other !!!!!!!!!!!!!!!!!!!!!1
    Was the "another widget" a headerview as well?

    Re: Drag and Drop problem
    actually I've a new surprise for u all. On debugging I found that it stops @ the break point in the mimeType of my temp small model. and i doesn't in the other model I've been working with for a while. So, I'd really appreciate if any body told me what the heck on earth could make what's happening here make sense !!!!
    mimeTypes() just lists what types are produced by the model, it's not important for drops. You have to check whether drop actions are enabled over the place you want to drop on. The difference in behaviour between "two models" could be caused by a different implementation of the flags() method.

    AFAIR normally a model doesn't differenciate between a drop on the header and "outside any item", so if you want to actually make a drop on the header, you have to hack the view (remember that headers are not part of the model).

    For instance, if you return ItemIsDropEnabled from flags() for an invalid index, you'll be able to perform a drop directly on the view (and not on any of its items). But this won't be a drop on the header itself - you'll be able to drop anywhere in the view. I thought you wanted to drop on the header explicitely.

    sorry but i think u've missed those to comments which I've posted early.
    I haven't missed them, I just thought they didn't carry any relevant information.

  15. #15
    Join Date
    Nov 2006
    Posts
    15

    Default Re: Drag and Drop problem

    for your first question yes it had a headerview.

    in both cases i used the same custom control I've made. So, what do u think might have caused this problem ?!

  16. #16
    Join Date
    May 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag and Drop problem

    Hello all,

    I am using QTableView with Qt4.6 and I have the same issue with Drop on QHeaderView.

    I have Drag & drop working nicely on the table but not on the header. I have created a new class that is based on QHeaderView and that implement the dragEnterEvent, dragMoveEvent, dropEvent.
    Of course I have setAcceptDrops(true).
    None of the the implemented event is called, and dropping data to the header is impossible...

    What I would like to do is to enable drag&drop for a complete line, by using the header.

    Does anyone have any idea or hint ?

    Thanks in advance

    kpa

  17. #17
    Join Date
    May 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag and Drop problem

    Finally it was only a bad validity check in dragEnterEvent

Similar Threads

  1. Drag & drop with model/view (Qt4)
    By yogeshm02 in forum Qt Programming
    Replies: 16
    Last Post: 19th September 2011, 20:36
  2. Replies: 7
    Last Post: 8th September 2006, 16:19
  3. Drag and drop outside the application
    By jpn in forum Newbie
    Replies: 7
    Last Post: 27th August 2006, 15:37
  4. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41
  5. Drag 'n Drop problem
    By kiker99 in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2006, 16:35

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.