Results 1 to 5 of 5

Thread: Drag&Drop with QStandardItemModel

  1. #1
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Drag&Drop with QStandardItemModel

    Hi,
    I have a QListView, which is linked to a QStandardItemModel. I'd like to be able to drop files on that QListView. The problem is, the supportedDropActions method is not supported by this object. This is quite strange, since it inherits QAbstractItemModel which provides this function. Is there a way to do drag & drop with QStandardItemModel ?
    Thanks in advance

  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&Drop with QStandardItemModel

    Subclass QStandardItemModel and reimplement the desired method. BTW. "supportedDropActions" returns Qt::CopyAction by default. So you should be able to drop data on it. Maybe you didn't enable dropping in the view?

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

    madcat (6th May 2006)

  4. #3
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag&Drop with QStandardItemModel

    Hi. Thanks for your answer.
    Actually, that's more the supportedDropActions which is intersting me, if I subclass QStandardItemModel, what should be the constructor ? Is this correct ? (I'm usually a C coder) :
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class PeerListModel : public QStandardItemModel {
    4. Q_OBJECT
    5. public:
    6. PeerListModel (QWidget *parent = 0);
    7. };
    8.  
    9. PeerListModel::PeerListModel (QWidget *parent = 0) {
    10. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag&Drop with QStandardItemModel

    Quote Originally Posted by madcat
    Is this correct ?
    Not quite, it should be:
    Qt Code:
    1. #include <QStandardItemModel>
    2.  
    3. class PeerListModel : public QStandardItemModel
    4. {
    5. Q_OBJECT
    6. public:
    7. PeerListModel( QObject *parent = 0 );
    8. };
    9.  
    10. PeerListModel::PeerListModel( QObject *parent ) : QStandardItemModel( parent )
    11. {
    12. }
    To copy to clipboard, switch view to plain text mode 
    Remember that if the constructor's implementation is in a header file, you should add "inline" keyword in front of it.

  6. The following user says thank you to jacek for this useful post:

    madcat (7th May 2006)

  7. #5
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag&Drop with QStandardItemModel

    Hi,
    actually it is not in the header file, I just pasted both files merged.
    Anyway, your solution works just great
    Once again, thank you a lot for your help

Similar Threads

  1. Replies: 2
    Last Post: 24th August 2008, 14:42
  2. QStandardItemModel insertRow crashing
    By munna in forum Qt Programming
    Replies: 1
    Last Post: 27th June 2008, 11:55
  3. QStandardItemModel limits
    By baray98 in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2008, 09:51
  4. qtableview QStandardItemModel read only
    By JeanC in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2008, 16:42
  5. QStandardItemModel: copy and append
    By davisjamesf in forum Newbie
    Replies: 1
    Last Post: 19th September 2007, 16:23

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.