1

I am looking for a way to disable -not hide- a specific section of header in a QTableView, I have already found a method that disables all the sections:

tableView.horizontalHeader().setDisabled(True)
tableView.verticalHeader().setDisabled(True)

but I need to disable only a 'specific' section.

Edit:

The header in the image below is disabled by the method call QHeaderView.setDisabled(True).

I just want to disable the last section of the header -not all of them-, and there's no need to disable the section's corresponding cells.

And by disable, I mean disable all of the selection, hovering, sorting,... behaviors.

Example of QtableView with a disabled header

CR4xR3V
  • 27
  • 9
  • 2
    if your intention to disable a specific header is to disable the sorting for particular column, then this [link](http://stackoverflow.com/questions/21973912/pyqt-qt4-qtableview-how-to-disable-sorting-for-certain-columns) will help – Jeet Feb 04 '16 at 18:30
  • You can use Qt Creator to test out different fields of QTableview, property editor. – m. c. Feb 04 '16 at 19:16
  • @Jeet : the header I'm attending to disable is an empty column, so I was thinking if I disable it, it would be nicer and less coding as I didn't want to handle it. thanks anyway. – CR4xR3V Feb 04 '16 at 20:51
  • @user3183610 I've already checked Qt designer, but no luck finding what I'm looking for, but maybe in Qt Creator I can find something, I'll give it a try. – CR4xR3V Feb 04 '16 at 20:55
  • 1
    If I understand you right, you should change the title of your question to something like *How to disable a specific section of header in QTableView.* – Tomas Feb 05 '16 at 11:34
  • In C++ I would suggest you to reimplement the `QHeaderView::paintSection()` method to paint a specified section as *disabled* and `QAbstractItemModel::sort()` method to disable sorting for that section, but I am not sure how much is it possible with PyQt. – Tomas Feb 05 '16 at 11:41
  • @M.Crax. Your question is very unclear. What kind of model are you using with the table? What *specific* behaviour of the header do you want to disable? And what about the cells in the corresponding column - should they also be disabled? – ekhumoro Feb 05 '16 at 18:32
  • @ekhumoro. I've added an image and I did make some clarification. And by the way, I'm using a QAbstractTableModel. – CR4xR3V Feb 05 '16 at 20:19
  • @M.Crax. I tried with `QStandardItemModel` to set a header item, and then use `horizontalHeaderItem(index).setEnabled(False)` - but this had no effect. So I suspect this just may not be possible. With a custom model, you'd need to get the index of a header in order to change its flags - but I can't see any way to do that (and it probably wouldn't work anyway). – ekhumoro Feb 06 '16 at 18:04
  • @ekhumoro. Thanks for your effort. It's just that there is no *direct* way to disable a section of header, but maybe with some method re-implementations you can change *some* behaviors. Anyway, I've wasted much time on this problem, I must keep going. – CR4xR3V Feb 06 '16 at 21:03

0 Answers0