PDA

View Full Version : QTableView sorting with verticalHeader()



lonik
11th March 2010, 18:26
Hi,

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






forumCModel = new QSqlTableModel(this);
forumCModel->setTable("ForumCatalogs");
forumCModel->setHeaderData(ForumCatalog_Id, Qt::Horizontal, tr("id"));
forumCModel->setHeaderData(ForumCatalog_Title, Qt::Horizontal, tr("Title"));
forumCModel->setHeaderData(ForumCatalog_Url, Qt::Horizontal, tr("Url"));
forumCModel->setHeaderData(ForumCatalog_HtmlData, Qt::Horizontal, tr("HtmlData"));


MyProxyModel = new QSortFilterProxyModel(this);
MyProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
MyProxyModel->setSourceModel(forumCModel);


forumCModel->select();

ui->tableViewFCatalogs->setModel(MyProxyModel);

ui->tableViewFCatalogs->setSelectionMode(QAbstractItemView::SingleSelectio n);
ui->tableViewFCatalogs->setSelectionBehavior(QAbstractItemView::SelectRows );
ui->tableViewFCatalogs->setSortingEnabled(true);
ui->tableViewFCatalogs->resizeColumnsToContents();
ui->tableViewFCatalogs->setEditTriggers(QAbstractItemView::NoEditTriggers) ;

headerForumCModel = ui->tableViewFCatalogs->horizontalHeader();
headerForumCModel->setStretchLastSection(true);
headerForumCModel->setSortIndicator(1,Qt::AscendingOrder);
Does anyone can tell me how to lock verticalHeader?

waynew
11th March 2010, 22:56
Where is your vertical header?

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

ChrisW67
12th March 2010, 08:48
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.

waynew
12th March 2010, 21:57
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?