Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtableView the sorting sign on the horizontal header

QtableView the sorting sign on the horizontal header

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 3.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    Hi All
    I have a QTableView , I am using following code

    errorTableView = 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

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qt Enthusiast
      wrote on last edited by
      #2

      Hi All
      I have a QTableView , I am using following code

      errorTableView = 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

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        your model modelis 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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Are there any data to sort ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved