Results 1 to 20 of 21

Thread: Can I get a drag&drop tobe displayed as a line instead of the big floating icon?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default Re: Can I get a drag&drop tobe displayed as a line instead of the big floating icon?

    Quote Originally Posted by wysota
    .../ Or you could even do it even more properly and encode not the index of the item but its data (as should be done with "real" drag&drop).
    This fit my purposes best, I think. The only thing my indexes containt is a pointer to a component in my scene. So it should be sufficuent to give this pointer as information... this was actually my first approach but I couldn't find how I was supposted to convert the pointer to a QByteArray and back.

    But there is one problem with this approach. I need to be able to remove the old index when the user have dropped the object, since it should be executed as a move action. So I need to find that index, and then I suppose I need to know its row and parent, and the parent's row and parent etc... maybe it's simpler to have a pointer in my model class pointing to the index being dragged and use this information instead of a mime. Could this create problems somehow?

    /pir
    Last edited by pir; 22nd May 2006 at 07:27.

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

    Default Re: Can I get a drag&drop tobe displayed as a line instead of the big floating icon?

    Quote Originally Posted by pir
    This fit my purposes best, I think. The only thing my indexes containt is a pointer to a component in my scene. So it should be sufficuent to give this pointer as information... this was actually my first approach but I couldn't find how I was supposted to convert the pointer to a QByteArray and back.
    A pointer is an integer, just treat it as such. But if you want to encode the data itself, then I didn't mean a pointer here, but actual information which is stored in an object referenced by the pointer.


    But there is one problem with this approach. I need to be able to remove the old index when the user have dropped the object, since it should be executed as a move action.
    I guess the view might do it yourself if you convince it you are doing a move action (but I'm not sure, haven't tried it myself yet).

    So I need to find that index, and then I suppose I need to know its row and parent, and the parent's row and parent etc...
    That's why the concept of indexes exists But if you implement the drop correctly, you won't have to worry about removing the item from its original place.

    maybe it's simpler to have a pointer in my model class pointing to the index being dragged and use this information instead of a mime. Could this create problems somehow?
    This doesn't give you any advantage. You can store the pointer in the QMimeData object as well.

  3. The following user says thank you to wysota for this useful post:

    pir (22nd May 2006)

  4. #3
    Join Date
    Aug 2006
    Posts
    163
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 5 Times in 4 Posts

    Default Re: Can I get a drag&drop tobe displayed as a line instead of the big floating icon?

    What may help you a bit is to look at my source code here : http://code.google.com/p/knewz/source/browse/trunk
    I ran into this the other day, it's a bit of work to get right but not terribly complicated once you get the hang of it. There's a few things to remember while dragging and dropping stuff, but you should be able to pick them up from my code if you haven't already.
    There pertinant stuff you will want to look at is the model and the mimedata implementations:
    http://code.google.com/p/knewz/sourc...knewzmodel.cpp
    http://code.google.com/p/knewz/sourc...zbmimedata.cpp

    Like you, I am just passing pointers to objects around in a QList. So with a drag and drop you just dump the pointer list into a custom mimedata class and retrieve it when it is dropped. Then you can use your underlying data structure to manipulate the data directly, encapsulating any removal and insertion of rows with the correct calls to being/endRemoveRows and begin/endInsertRows

Similar Threads

  1. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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.