Qt World Summit: Register Today!

With QTableView, can I have the vertical header always be visible, even when the table is empty?

  • I have a QTableView that displays both a horizontal and vertical header. When the table is empty (i.e. there are no rows), the horizontal header at the top is still visible, but the vertical header disappears. I'd like it if I could have it so that the vertical header is always visible. Is there any way to do that?

  • Lifetime Qt Champion


    The only way I currently see it is you have to make your model lie to the view.

    What is your use case ?

  • @SGaist It's not a use case so much as when the table view displays data after being empty, there's a noticeable but short fraction of a second where all of the cells are drawn but the vertical header isn't there, and then it redraws with the vertical header. The discontinuity is subtly jarring and I think it looks unprofessional, so I was wondering if I could just have the vertical header always be visible. It's more visually consistent too since the horizontal header is visible all of the time.

    If I can't do that, if it's possible to fix the discontinuity so that the vertical header draws at the same time as the cells, that would also be acceptable. And failing that, I can live with there being this visual discontinuity. I'd just prefer it wasn't there.

  • Lifetime Qt Champion

    Part of if might depend on how you are managing your data.

    Are you emptying the widget and replace the content of it or should it stay empty for a while ?

  • @SGaist
    When you search the table and there is no data match, the veritcal will be hidden , I also need to display it always.
    I already subclass from QSqlTableModel and implement headerData() for some feature, but how to make the vetical header always be visible?

  • Lifetime Qt Champion

    Full range ?

  • @SGaist
    did not get it what you mean.

  • Lifetime Qt Champion

    You are asking for the header to be always visible, but does it need to show the whole range ?
    By the way, could you provide a minimal compilable example so that it's possible to test/validate the behaviour ?

Log in to reply