Results 1 to 4 of 4

Thread: QTableView sorting with verticalHeader()

  1. #1
    Join Date
    Mar 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableView sorting with verticalHeader()

    Hi,

    I have problem that when i use QSortFilterProxyModel, QSqlTableModel, QTableView i tableView the verticalHeader also is soring so is treaded as column :-(




    Qt Code:
    1. forumCModel = new QSqlTableModel(this);
    2. forumCModel->setTable("ForumCatalogs");
    3. forumCModel->setHeaderData(ForumCatalog_Id, Qt::Horizontal, tr("id"));
    4. forumCModel->setHeaderData(ForumCatalog_Title, Qt::Horizontal, tr("Title"));
    5. forumCModel->setHeaderData(ForumCatalog_Url, Qt::Horizontal, tr("Url"));
    6. forumCModel->setHeaderData(ForumCatalog_HtmlData, Qt::Horizontal, tr("HtmlData"));
    7.  
    8.  
    9. MyProxyModel = new QSortFilterProxyModel(this);
    10. MyProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
    11. MyProxyModel->setSourceModel(forumCModel);
    12.  
    13.  
    14. forumCModel->select();
    15.  
    16. ui->tableViewFCatalogs->setModel(MyProxyModel);
    17.  
    18. ui->tableViewFCatalogs->setSelectionMode(QAbstractItemView::SingleSelection);
    19. ui->tableViewFCatalogs->setSelectionBehavior(QAbstractItemView::SelectRows);
    20. ui->tableViewFCatalogs->setSortingEnabled(true);
    21. ui->tableViewFCatalogs->resizeColumnsToContents();
    22. ui->tableViewFCatalogs->setEditTriggers(QAbstractItemView::NoEditTriggers);
    23.  
    24. headerForumCModel = ui->tableViewFCatalogs->horizontalHeader();
    25. headerForumCModel->setStretchLastSection(true);
    26. headerForumCModel->setSortIndicator(1,Qt::AscendingOrder);
    To copy to clipboard, switch view to plain text mode 
    Does anyone can tell me how to lock verticalHeader?

  2. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView sorting with verticalHeader()

    Where is your vertical header?

    Your code says: headerForumCModel = ui->tableViewFCatalogs->horizontalHeader();

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTableView sorting with verticalHeader()

    I think the issue that lonik is describing is that when you use the horizontal header to sort your table on a given column the vertical header labels, which are the row (logical index) number, move with their row. The result is that the vertical header labels are not in order like you would see in, for example, Excel when your sort the data. I think the way around this might be a QHeaderView derivative that used the visual index of the row for the label rather than the logical index.

  4. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView sorting with verticalHeader()

    Ok Chris, I see what he means now. I just set the header column titles with model->setHeaderData(n, Qt::Horizontal, "Col_Name")
    If he can do that, no more problem, right?

Similar Threads

  1. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  2. QTableView sorting when using a model
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 13:13
  3. QTableView sorting problem
    By noktus in forum Newbie
    Replies: 11
    Last Post: 23rd April 2008, 10:20
  4. QTableView sorting
    By Bojan in forum Newbie
    Replies: 2
    Last Post: 28th September 2006, 08:11
  5. Sorting QTableView
    By Jimmy2775 in forum Qt Programming
    Replies: 7
    Last Post: 9th February 2006, 16:47

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
  •  
Qt is a trademark of The Qt Company.