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 sort indicator not shows

QTableView sort indicator not shows

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 5 Posters 3.1k Views
  • 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.
  • jronaldJ Offline
    jronaldJ Offline
    jronald
    wrote on last edited by jronald
    #1
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        ui->tableView_evaluator->setModel(&tableModel_evaluator);
    
        bool b = ui->tableView_evaluator->isSortingEnabled();
        Q_ASSERT(b);
    
        ui->tableView_evaluator->sortByColumn(3, Qt::AscendingOrder);
    
    ////  another method, not work
    //    QHeaderView * hh = ui->tableView_evaluator->horizontalHeader();
    //    hh->setSortIndicator(3, Qt::AscendingOrder);
    //    hh->setSortIndicatorShown(true);
    }
    

    Everything is normal except that the sort indicator does not show.
    What is the problem?

    screenshot

    BTW, no grid line below horizontal headers, also none for vertical headers, why?

    Env:

    • Qt 5.13.1 AMD64
    • OS: Manjaro xfce AMD64
    JonBJ 1 Reply Last reply
    0
    • jronaldJ jronald
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          ui->tableView_evaluator->setModel(&tableModel_evaluator);
      
          bool b = ui->tableView_evaluator->isSortingEnabled();
          Q_ASSERT(b);
      
          ui->tableView_evaluator->sortByColumn(3, Qt::AscendingOrder);
      
      ////  another method, not work
      //    QHeaderView * hh = ui->tableView_evaluator->horizontalHeader();
      //    hh->setSortIndicator(3, Qt::AscendingOrder);
      //    hh->setSortIndicatorShown(true);
      }
      

      Everything is normal except that the sort indicator does not show.
      What is the problem?

      screenshot

      BTW, no grid line below horizontal headers, also none for vertical headers, why?

      Env:

      • Qt 5.13.1 AMD64
      • OS: Manjaro xfce AMD64
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @jronald said in QTableView sort indicator not shows:
      You will definitely need the version which calls setSortIndicatorShown(true), since https://doc.qt.io/qt-5/qheaderview.html#showSortIndicator-prop states that the default is false.

      So you need your commented-out code. It should work. If you say it does not, try moving the sortByColumn() to after the setSortIndicator...() lines, though I don't think that will make any difference.

      You might also try calling hh->setSectionsClickable(true) to see whether clicking makes the indicator visible for you, though again I don't think you should have to do that.

      jronaldJ 1 Reply Last reply
      0
      • JonBJ JonB

        @jronald said in QTableView sort indicator not shows:
        You will definitely need the version which calls setSortIndicatorShown(true), since https://doc.qt.io/qt-5/qheaderview.html#showSortIndicator-prop states that the default is false.

        So you need your commented-out code. It should work. If you say it does not, try moving the sortByColumn() to after the setSortIndicator...() lines, though I don't think that will make any difference.

        You might also try calling hh->setSectionsClickable(true) to see whether clicking makes the indicator visible for you, though again I don't think you should have to do that.

        jronaldJ Offline
        jronaldJ Offline
        jronald
        wrote on last edited by
        #3

        @JonB

        Still no shown

        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent), ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
            QHeaderView * hh = ui->tableView_evaluator->horizontalHeader();
        
            hh->setSortIndicatorShown(true);
        
            ui->tableView_evaluator->setModel(&tableModel_evaluator);
        
            hh->setSortIndicatorShown(true);
        
            bool b = ui->tableView_evaluator->isSortingEnabled();
            Q_ASSERT(b);
        
            ui->tableView_evaluator->sortByColumn(3, Qt::AscendingOrder);
        
            hh->setSortIndicatorShown(true);
        }
        
        JonBJ 1 Reply Last reply
        0
        • jronaldJ jronald

          @JonB

          Still no shown

          MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent), ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
              QHeaderView * hh = ui->tableView_evaluator->horizontalHeader();
          
              hh->setSortIndicatorShown(true);
          
              ui->tableView_evaluator->setModel(&tableModel_evaluator);
          
              hh->setSortIndicatorShown(true);
          
              bool b = ui->tableView_evaluator->isSortingEnabled();
              Q_ASSERT(b);
          
              ui->tableView_evaluator->sortByColumn(3, Qt::AscendingOrder);
          
              hh->setSortIndicatorShown(true);
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @jronald
          I'd also put in a

          hh->setSortIndicator(3, Qt::AscendingOrder);
          

          before the last setSortIndicatorShown(). (You can remove the earlier calls to setSortIndicatorShown().)

          Humour me: I see your Q_ASSERT() (you aren't compiling for no-debug, are you?), but try putting in an explicit ui->tableView_evaluator->setSortingEnabled(true).

          jronaldJ 1 Reply Last reply
          0
          • JonBJ JonB

            @jronald
            I'd also put in a

            hh->setSortIndicator(3, Qt::AscendingOrder);
            

            before the last setSortIndicatorShown(). (You can remove the earlier calls to setSortIndicatorShown().)

            Humour me: I see your Q_ASSERT() (you aren't compiling for no-debug, are you?), but try putting in an explicit ui->tableView_evaluator->setSortingEnabled(true).

            jronaldJ Offline
            jronaldJ Offline
            jronald
            wrote on last edited by
            #5

            @JonB said in QTableView sort indicator not shows:

            @jronald
            I'd also put in a

            hh->setSortIndicator(3, Qt::AscendingOrder);
            

            before the last setSortIndicatorShown().

            Still not work

            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent), ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            
                QHeaderView * hh = ui->tableView_evaluator->horizontalHeader();
            
                hh->setSortIndicatorShown(true);
            
                ui->tableView_evaluator->setModel(&tableModel_evaluator);
            
                hh->setSortIndicatorShown(true);
            
                ui->tableView_evaluator->setSortingEnabled(true);
                bool b = ui->tableView_evaluator->isSortingEnabled();
                Q_ASSERT(b);
            
            //    ui->tableView_evaluator->sortByColumn(3, Qt::AscendingOrder);
            
                hh->setSortIndicator(3, Qt::AscendingOrder);
            
                hh->setSortIndicatorShown(true);
            }
            

            Humour me: I see your Q_ASSERT() (you aren't compiling for no-debug, are you?), but try putting in an explicit ui->tableView_evaluator->setSortingEnabled(true).

            Compiling in debug mode, I've set it to true in UI designer.

            JonBJ 1 Reply Last reply
            0
            • jronaldJ jronald

              @JonB said in QTableView sort indicator not shows:

              @jronald
              I'd also put in a

              hh->setSortIndicator(3, Qt::AscendingOrder);
              

              before the last setSortIndicatorShown().

              Still not work

              MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent), ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
              
                  QHeaderView * hh = ui->tableView_evaluator->horizontalHeader();
              
                  hh->setSortIndicatorShown(true);
              
                  ui->tableView_evaluator->setModel(&tableModel_evaluator);
              
                  hh->setSortIndicatorShown(true);
              
                  ui->tableView_evaluator->setSortingEnabled(true);
                  bool b = ui->tableView_evaluator->isSortingEnabled();
                  Q_ASSERT(b);
              
              //    ui->tableView_evaluator->sortByColumn(3, Qt::AscendingOrder);
              
                  hh->setSortIndicator(3, Qt::AscendingOrder);
              
                  hh->setSortIndicatorShown(true);
              }
              

              Humour me: I see your Q_ASSERT() (you aren't compiling for no-debug, are you?), but try putting in an explicit ui->tableView_evaluator->setSortingEnabled(true).

              Compiling in debug mode, I've set it to true in UI designer.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @jronald
              Don't know then. https://stackoverflow.com/questions/43535789/how-to-set-sort-indicator-for-qtableview-programatically reports the same as you, but was never answered if the indicators truly do not show for that user. It shows the principle of what you're supposed to write. There seem to be plenty of others for whom indicators are working fine. You're not using any special "skin"/"theme" on your platform (which is what?)? Or some table style or something which might not show the indicators?

              P.S.
              Last thing: try a setSectionsClickable(true), just in case that influences...?

              jronaldJ 1 Reply Last reply
              0
              • JonBJ JonB

                @jronald
                Don't know then. https://stackoverflow.com/questions/43535789/how-to-set-sort-indicator-for-qtableview-programatically reports the same as you, but was never answered if the indicators truly do not show for that user. It shows the principle of what you're supposed to write. There seem to be plenty of others for whom indicators are working fine. You're not using any special "skin"/"theme" on your platform (which is what?)? Or some table style or something which might not show the indicators?

                P.S.
                Last thing: try a setSectionsClickable(true), just in case that influences...?

                jronaldJ Offline
                jronaldJ Offline
                jronald
                wrote on last edited by jronald
                #7

                @JonB said in QTableView sort indicator not shows:

                @jronald
                Don't know then. https://stackoverflow.com/questions/43535789/how-to-set-sort-indicator-for-qtableview-programatically reports the same as you, but was never answered if the indicators truly do not show for that user. It shows the principle of what you're supposed to write. There seem to be plenty of others for whom indicators are working fine. You're not using any special "skin"/"theme" on your platform (which is what?)? Or some table style or something which might not show the indicators?

                No, a demo simply for testing.

                P.S.
                Last thing: try a setSectionsClickable(true), just in case that influences...?

                Tried, failed.

                JonBJ 1 Reply Last reply
                0
                • jronaldJ jronald

                  @JonB said in QTableView sort indicator not shows:

                  @jronald
                  Don't know then. https://stackoverflow.com/questions/43535789/how-to-set-sort-indicator-for-qtableview-programatically reports the same as you, but was never answered if the indicators truly do not show for that user. It shows the principle of what you're supposed to write. There seem to be plenty of others for whom indicators are working fine. You're not using any special "skin"/"theme" on your platform (which is what?)? Or some table style or something which might not show the indicators?

                  No, a demo simply for testing.

                  P.S.
                  Last thing: try a setSectionsClickable(true), just in case that influences...?

                  Tried, failed.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @jronald
                  OK. At this point: I can't help because I'm not C++, but:

                  • Can you produce a 20-liner minimal (2 data rows) complete which compiles? So someone can just paste and try.
                  • Tell us what version of Qt and what platform.
                  • Request someone kind who fancies compiling. @mrjj is known to be very helpful at trying other people's UI stuff. :) :)
                  • Compare their result to yours.
                  • If it truly turns out to be inexplicable, make post on Qt bug forum.
                  jronaldJ 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @jronald
                    OK. At this point: I can't help because I'm not C++, but:

                    • Can you produce a 20-liner minimal (2 data rows) complete which compiles? So someone can just paste and try.
                    • Tell us what version of Qt and what platform.
                    • Request someone kind who fancies compiling. @mrjj is known to be very helpful at trying other people's UI stuff. :) :)
                    • Compare their result to yours.
                    • If it truly turns out to be inexplicable, make post on Qt bug forum.
                    jronaldJ Offline
                    jronaldJ Offline
                    jronald
                    wrote on last edited by jronald
                    #9

                    @JonB said in QTableView sort indicator not shows:

                    • Can you produce a 20-liner minimal (2 data rows) complete which compiles? So someone can just paste and try.

                    ![0_1572462658913_TestQt.tar.bz2.png](Uploading 100%)
                    PS: rename to TestQt.tar.bz2
                    PS: cheating failed, the project can't be downloaded

                    • Tell us what version of Qt and what platform.
                    • Qt 5.13.1 AMD64
                    • OS: Manjaro xfce AMD64
                    • Request someone kind who fancies compiling. @mrjj is known to be very helpful at trying other people's UI stuff. :) :)
                    • Compare their result to yours.

                    I'll try it on Winows later.

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      No need to upload something (it doesn't work) - 10 lines of code are enough:

                      #include <QtWidgets>
                      int main(int argc, char **argv)
                      {
                          QApplication app(argc, argv);
                          
                          QStringListModel model({"A", "B", "C", "D", "E", "F"});
                          QTableView tv;
                          tv.setModel(&model);
                          tv.setSortingEnabled(true);
                          tv.horizontalHeader()->setSortIndicatorShown(true);
                          tv.show();
                          return app.exec();
                      }
                      

                      This is working fine for me.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      jronaldJ 1 Reply Last reply
                      4
                      • Christian EhrlicherC Christian Ehrlicher

                        No need to upload something (it doesn't work) - 10 lines of code are enough:

                        #include <QtWidgets>
                        int main(int argc, char **argv)
                        {
                            QApplication app(argc, argv);
                            
                            QStringListModel model({"A", "B", "C", "D", "E", "F"});
                            QTableView tv;
                            tv.setModel(&model);
                            tv.setSortingEnabled(true);
                            tv.horizontalHeader()->setSortIndicatorShown(true);
                            tv.show();
                            return app.exec();
                        }
                        

                        This is working fine for me.

                        jronaldJ Offline
                        jronaldJ Offline
                        jronald
                        wrote on last edited by jronald
                        #11

                        @Christian-Ehrlicher
                        Thank you
                        It doesn't work for me.
                        ascend.png
                        descend.png

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          What style is this? Did you compile Qt by yourself? Please try with fusion style ("-style fusion")

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          jronaldJ 1 Reply Last reply
                          0
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Hi
                            Just as a note.
                            works on Win 10.
                            alt text
                            Linux Mint
                            alt text

                            so it seems related to Arch linux.

                            1 Reply Last reply
                            4
                            • Christian EhrlicherC Christian Ehrlicher

                              What style is this? Did you compile Qt by yourself? Please try with fusion style ("-style fusion")

                              jronaldJ Offline
                              jronaldJ Offline
                              jronald
                              wrote on last edited by jronald
                              #14

                              @Christian-Ehrlicher said in QTableView sort indicator not shows:

                              What style is this?

                              default style of Manjaro xfce

                              Did you compile Qt by yourself?

                              No, installed by pacman

                              Please try with fusion style ("-style fusion")

                              Do you mean compile Qt with -style fusion?

                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Offline
                                Christian EhrlicherC Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @jronald said in QTableView sort indicator not shows:

                                Compile Qt with -style fusion?

                                No, start the app with this parameter.

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

                                jronaldJ 1 Reply Last reply
                                2
                                • Christian EhrlicherC Christian Ehrlicher

                                  @jronald said in QTableView sort indicator not shows:

                                  Compile Qt with -style fusion?

                                  No, start the app with this parameter.

                                  jronaldJ Offline
                                  jronaldJ Offline
                                  jronald
                                  wrote on last edited by jronald
                                  #16

                                  @Christian-Ehrlicher said in QTableView sort indicator not shows:

                                  @jronald said in QTableView sort indicator not shows:

                                  Compile Qt with -style fusion?

                                  No, start the app with this parameter.

                                  a.png
                                  Nice, any way to built in the style?
                                  BTW, "Qt5 Settings (Qt5 Configuration Tool)" can change the style used by the demo.

                                  Thanks

                                  1 Reply Last reply
                                  0
                                  • VRoninV Offline
                                    VRoninV Offline
                                    VRonin
                                    wrote on last edited by VRonin
                                    #17

                                    In your main() put QApplication::setStyle(QStyleFactory::create("Fusion"));

                                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                    ~Napoleon Bonaparte

                                    On a crusade to banish setIndexWidget() from the holy land of Qt

                                    1 Reply Last reply
                                    5

                                    • Login

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