Qt World Summit: Submit your Presentation

How to change column header titles when using one model with multiple table views

  • Hi,

    I have a custom QAbstractItemModel based model and 4 QTableViews. Each table view uses the same model object.

    I would like to rename the horizontal header sections for each table differently. The models headerData() method unfortunately doesn't help, it would change the header titles for all of them at once.

    Any ideas?


  • How about using your own QHeaderView derived class where you can handle its working differently ?
    You can set your header view using setHorizontalHeaderView/setVerticalHeaderView func.

  • I would use proxy models for each of your views. If you are on Qt 4.8, use [[doc:QIdentityProxyModel]] as the base for such proxies, if you are on Qt 4.7 or lower, use [[doc:QSortFilterProxyModel]] instead. In the proxy model, you simply reimplement the headerData() method to return whatever you need.

Log in to reply