Results 1 to 2 of 2

Thread: proxy model, selection not visible in a table view (QTableView,QSortFilterProxyModel)

  1. #1
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default proxy model, selection not visible in a table view (QTableView,QSortFilterProxyModel)

    Hi,

    I'm presenting model data in a MyTableView (subclassed from QTableView), which has the following selection settings:
    mView->setSelectionBehavior(QAbstractItemView::SelectRow s);
    mView->setSelectionMode(QAbstractItemView::ExtendedSelec tion);

    Due to some other restrictions, my custom model is subclassed from QAbstractItemModel and is "projected" on QTableView through MySortFilterProxyModel subclassed from QSortFilterProxyModel.

    In custom model I've reimplemented: index, parent, rowCount, columnCount, data, setData, flags, setHeaderData, headerData. In custom proxy model I've reimplemented: index, parent, rowCount, columnCount, data, filterAcceptsRow, filterAcceptsColumn, lessThan, flags, mapFromSource, mapToSource.

    The problem is that MyTableView doesn't show anything selected (I always see unselected rows) even though the debug printout from its indexAt(...) shows correctly what model index the mouse is clicking/moving over.

    After playing around a bit with different configurations I could see selected rows in MyTableView but only when I removed MyProxyModel or removed and replaced MyItemModel with QStandardItemModel.

    1. No selection is visible in MyTableView (although I'm getting data from correct model indices):

    QAbstractItemModel...........QSortFilterProxyModel ...........QTableView
    .............|.................................... .......|................................|
    .............|.................................... .......|................................|
    ....MyItemModel -----------------> MyProxyModel --------> MyTableView (result: ExtendedSelection set but no selection visble at all)


    2. Rows are visibly selected in MyTableView (although ExtendedSelection doesn't work - multple rows can be selected only by Ctrl key + Left Mouse Button):

    QAbstractItemModel QTableView
    .............|.....................|
    .............|.....................|
    MyItemModel -----> MyTableView (result: ExtendedSelection set but single row selection only available)

    3. Selection works perfectly:

    ....................................QTableView
    ............................................|
    ............................................|
    QStandardItemModel -> MyTableView (result: ExtendedSelection set and works perfectly)

    What am I missing?
    Thanks in advance for any suggestions.
    W.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: proxy model, selection not visible in a table view (QTableView,QSortFilterProxyMo

    I realize this is an old post, but did you find a solution?

    I am seeing exactly the same problem. The proxy model documentation and examples is just too sparse to give any clues as to what is wrong.

    -- Later: Never mind --

    I got a hint from reading another post here; I implemented flags() in my proxy to return what QAbstractItemModel *says* is the default, but apparently isn't: ItemIsEnabled | ItemIsSelectable. When I did that, all works.
    Last edited by d_stranz; 19th November 2009 at 00:51.

Similar Threads

  1. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 07:45
  2. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 09:50
  3. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 12:03

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.