Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTableView sort indicator not shows



  • 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


  • @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.



  • @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);
    }
    


  • @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).



  • @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.



  • @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...?



  • @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.



  • @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.


  • @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.


  • Lifetime Qt Champion

    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.



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


  • Lifetime Qt Champion

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


  • Lifetime Qt Champion

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

    so it seems related to Arch linux.



  • @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?


  • Lifetime Qt Champion

    @jronald said in QTableView sort indicator not shows:

    Compile Qt with -style fusion?

    No, start the app with this parameter.



  • @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



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


Log in to reply