Results 1 to 10 of 10

Thread: selection in filterproxymodel

  1. #1
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question selection in filterproxymodel

    Hi I have a question about how can I get selected rows indexes from QSortFilterProxyModel...(selection behaviour is set to select rows)
    in QTableView there is a possibility using this:
    msgTableView->selectionModel()->selectedRows()

    But when I have to models from which one is filtermodel and it has set second one using
    filterModel->setSourceModel(2ndmodel);
    then this method of getting a list of indexes is unuseful ...
    Can anyone help me to figure it out ?
    I think I have to map them somehow to source indexes but dont know how

  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: selection in filterproxymodel

    Selection is a property of the view, not of the model. If you set a proxy model on the view, you can use its selection model to get selected indexes of the proxy model which you can then map to the source model using its mapToSource() method.

  3. #3
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: selection in filterproxymodel

    Quote Originally Posted by wysota View Post
    Selection is a property of the view, not of the model. If you set a proxy model on the view, you can use its selection model to get selected indexes of the proxy model which you can then map to the source model using its mapToSource() method.
    Yes but I was actually asking if there is a method to which I would actually passed the whole index list got byt selectionModel()->selectedRows() instead of iterating over all indexes....

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: selection in filterproxymodel

    Take a closer look at QAbstractProxyModel docs.
    J-P Nurmi

  5. #5
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: selection in filterproxymodel

    Quote Originally Posted by jpn View Post
    Take a closer look at QAbstractProxyModel docs.
    man I made it work....but wanted something simpler...it wasnt hard of course...
    Qt Code:
    1. foreach(QModelIndex index, msgTableView->selectionModel()->selectedRows()){
    2. QModelIndex sourceIndex = filterModel->mapToSource(index);
    3. int row = sourceIndex.row();
    4. for(int i = 0; i < model->columnCount(); i++){
    5. QModelIndex index2 = model->index(row, i);
    6. QVariant prepMsg = model->data(index2);
    7. if(i == 0){
    8. sendMsg.id = prepMsg.toString().toULong();
    9. qDebug("Message id = %ld", sendMsg.id);
    10. }
    11. if(i == 1){
    12. sendMsg.flags = prepMsg.toString().toInt();
    13. qDebug("Message flags = %d", sendMsg.flags);
    14. }
    15. if(i == 2){
    16. QByteArray sendData = QByteArray::fromHex(prepMsg.toString().toAscii());
    17. int length = qMin(sendData.size(), CAN_MSG_LENGTH);
    18. qDebug("LENGTH = %d", length);
    19. memcpy(sendMsg.data, (const unsigned char*)sendData.constData(), length);
    20. sendMsg.length = length;
    21. }
    22. }
    23. parentWindow->getNetworkIfc()->sendCanMsg(&sendMsg);
    24. QVcaCanMsg sharedMsg(&sendMsg);
    25. emit msgHistoryEnqueue(sharedMsg);
    26. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: selection in filterproxymodel

    J-P Nurmi

  7. #7
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: selection in filterproxymodel

    Quote Originally Posted by jpn View Post
    damn it...yes thats better solution...I remade it your way...But BOTH solutions work
    Last edited by gyre; 4th December 2007 at 22:15.

  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: selection in filterproxymodel

    Doesn't it do exactly that?

  9. #9
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: selection in filterproxymodel

    Quote Originally Posted by wysota View Post
    Doesn't it do exactly that?
    damn it...I was talking about something different
    Last edited by gyre; 4th December 2007 at 22:12. Reason: updated contents

  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: selection in filterproxymodel

    Please don't modify your previous posts like that. It breaks the flow of the discussion and others can't benefit from it.

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  2. selection in QLineEdit
    By spigel in forum Qt Programming
    Replies: 10
    Last Post: 17th May 2007, 09:43
  3. QAbstractItemView selection behaviour issue
    By Caius Aérobus in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2007, 16:33
  4. CheckBox and selection in QTableView
    By Mike Krus in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 20:31
  5. QSortFilterProxyModel signal and selection confusion
    By pascal123 in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2006, 16: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.