QtableView the sorting sign on the horizontal header
-
Hi All
I have a QTableView , I am using following codeerrorTableView = new QTableView();
errorTableView->verticalHeader()->show();
errorTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
/we can select multiple rows with ctrl click/
errorTableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
errorTableView->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
errorTableView->horizontalHeader()->setStretchLastSection(true);
errorTableView->resizeColumnsToContents();proxyModel = new QSortFilterProxyModel;;
model = new QAbstractTableModel;
proxyModel->setSourceModel(modell);
errorTableView->setModel(d_proxyModel);
errorTableView->setSortingEnabled(true);
errorTableView->sortByColumn(0,Qt::AscendingOrder);
if(errorTableView->horizontalHeader()) {
errorTableView->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder);
}
I have only one column and sorting indicator (triangle) is not visible and we need to stretch the window for the same to get the sorting -
Hi All
I have a QTableView , I am using following codeerrorTableView = new QTableView();
errorTableView->verticalHeader()->show();
errorTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
/we can select multiple rows with ctrl click/
errorTableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
errorTableView->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
errorTableView->horizontalHeader()->setStretchLastSection(true);
errorTableView->resizeColumnsToContents();proxyModel = new QSortFilterProxyModel;;
model = new QAbstractTableModel;
proxyModel->setSourceModel(modell);
errorTableView->setModel(d_proxyModel);
errorTableView->setSortingEnabled(true);
errorTableView->sortByColumn(0,Qt::AscendingOrder);
if(errorTableView->horizontalHeader()) {
errorTableView->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder);
}
I have only one column and sorting indicator (triangle) is not visible and we need to stretch the window for the same to see the sorting indicator what should be done to get the sorting indicator visible in the QTableView also the errorTableView->horizontalHeader()->setStretchLastSection(true); should also be true as it is required -
Hi,
your model
model
is an QAbstractTableModel which is incorrect. You should subclass this class if you want to create your own model and follow the guidelines of the documentation about returning the size of the model. -
My code is
class myTableView : public QTableView
}class myModel: QAbstractTableModel {
}class sortProxyModel:public QSortFilterProxyModel {
}
errorTableView = new myQTableView();
errorTableView->verticalHeader()->show();
errorTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
/we can select multiple rows with ctrl click/
errorTableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
errorTableView->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
errorTableView->horizontalHeader()->setStretchLastSection(true);
errorTableView->resizeColumnsToContents();model = new myModell;
proxyModel = new SortProxyModel;;proxyModel->setSourceModel(modell);
errorTableView->setModel(d_proxyModel);
errorTableView->setSortingEnabled(true);
errorTableView->sortByColumn(0,Qt::AscendingOrder);
if(errorTableView->horizontalHeader()) {
errorTableView->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder);
}but still I am getting the issue that sorting indicator is not seen properly
-
Are there any data to sort ?