Results 1 to 3 of 3

Thread: Move items in a QSortFilterProxyModel

  1. #1
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Move items in a QSortFilterProxyModel

    I have a tableview with takes a qsortfilterproxymodel and is filtered by a particular name.

    I have subclassed the qsortfilterproxymodel
    Qt Code:
    1. class FilterProxyModel : public QSortFilterProxyModel
    2. {
    3. Q_OBJECT
    4. public:
    5. FilterProxyModel(QObject *parent = 0);
    6.  
    7. void moveUp( const int itemIndex);
    8. void moveDown( const int itemIndex);
    9. };
    To copy to clipboard, switch view to plain text mode 

    and here's the implementation
    Qt Code:
    1. FilterProxyModel ::FilterProxyModel (QObject *parent) :
    2. {
    3.  
    4. }
    5.  
    6. void FilterProxyModel ::moveUp(const int itemIndex)
    7. {
    8. if(itemIndex > 0 && itemIndex < rowCount())
    9. {
    10. beginMoveRows(QModelIndex(), itemIndex, itemIndex, QModelIndex(),
    11. itemIndex - 1);
    12. moveRow(QModelIndex(), itemIndex, QModelIndex(), itemIndex - 1);
    13. endMoveRows();
    14. }
    15. }
    16.  
    17. void FilterProxyModel ::moveDown(const int itemIndex)
    18. {
    19. if(itemIndex >= 0 && itemIndex < rowCount() - 1)
    20. {
    21. beginMoveRows(QModelIndex(), itemIndex, itemIndex, QModelIndex(),
    22. itemIndex + 2);
    23. moveRow(QModelIndex(), itemIndex, QModelIndex(), itemIndex + 2);
    24. endMoveRows();
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    Here's how the model implemented
    Qt Code:
    1. m_Model = new FilterProxyModel(this);
    2. m_Model ->setSourceModel(partiesModel);
    3. m_Model ->setFilterRegExp(QRegExp("party", Qt::CaseInsensitive, QRegExp::FixedString));
    4. m_Model ->setFilterKeyColumn(PartyModel::Action);
    To copy to clipboard, switch view to plain text mode 

    I want to move the items using a push button, when i call the function the move doesn't happen. Could you tell me what I'm missing?

  2. #2
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Move items in a QSortFilterProxyModel

    Check return value of moveRow() and shows that function.

  3. #3
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Move items in a QSortFilterProxyModel

    I will write a custom implementation of the move and try

Similar Threads

  1. Move items up and down in QListWidget
    By araglin in forum Newbie
    Replies: 7
    Last Post: 31st August 2016, 11:05
  2. Replies: 0
    Last Post: 26th June 2014, 14:03
  3. Moving Items in QTableView with QSortFilterProxyModel
    By Rudolf Rendier in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2012, 15:07
  4. Replies: 1
    Last Post: 9th August 2009, 19:51
  5. Can't move Items in the scene
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2008, 09:40

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.