Results 1 to 2 of 2

Thread: pressed(const QModelIndex &) signal gives the wrong index using QSortFilterProxyModel

  1. #1
    Join Date
    Apr 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: pressed(const QModelIndex &) signal gives the wrong index using QSortFilterProxyM

    Sorting visually works great using QTableView sort headers or custome soring implementation in QSortFilterProxyModel.

    But when I emit pressed(const QModelIndex &) signal it gives an index before the sort. so let say I have 3 rows,

    1
    2
    3

    pressed(const QModelIndex &) on 1 GIVES 1

    then sort the using table header.

    3
    2
    1

    pressed(const QModelIndex &) on 3 GIVES 1

    To get correct item from index I have used several methods, I was using also proxy model to get the item. I's all wrong, it just the pressed(const QModelIndex & INDEX ) INDEX is not right always gives me the index on row before SORTING.

    Currently I use this
    Qt Code:
    1. QStandardItem *item = model()->item(index.row(),0);
    To copy to clipboard, switch view to plain text mode 

    tried to get an index form proxy base on the clicked row.

    Qt Code:
    1. QModelIndex index = _proxyModel->index(indexs.row(),0,QModelIndex());
    To copy to clipboard, switch view to plain text mode 

    ONE MORE

    The index.row() is correct clicked on seconds row goves 2, it jast the data in there.

    Thoughts ?


    Added after 25 minutes:


    And here is a fix!

    http://stackoverflow.com/questions/3...lterproxymodel
    Last edited by migel; 4th October 2011 at 17:13.

  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: pressed(const QModelIndex &) signal gives the wrong index using QSortFilterProxyM

    Do you understand what the problem was? Are you aware that Qt acts properly and it's your incorrect code that was causing problems?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 4
    Last Post: 2nd March 2011, 09:03
  2. Replies: 0
    Last Post: 7th October 2010, 19:38
  3. Replies: 4
    Last Post: 10th December 2009, 14:54
  4. Replies: 6
    Last Post: 5th December 2007, 22:41
  5. QTreeView::doubleClicked(const QModelIndex&) signal
    By Vladimir in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2007, 09:25

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.