1

I am working with a table view where in I can select a row and it will open a new window after a double click. However, I don't want the header to be highlighted whenever I am clicking something on its cell.

self.memory_map_table.double_click_row(self._modify_row)

How to prevent table view horizontal header from being highlighted when I click a cell under it?

self.memory_map_table.horizontalHeader(). ...
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Tenserflu
  • 520
  • 5
  • 20

1 Answers1

1

One possible solution is to implement a QProxyStyle that overrides that highlight:

from PySide2 import QtCore, QtGui, QtWidgets


class HeaderProxyStyle(QtWidgets.QProxyStyle):
    def drawControl(self, element, option, painter, widget=None):
        if element == QtWidgets.QStyle.CE_Header:
            option.state &= ~QtWidgets.QStyle.State_On
            option.state &= ~QtWidgets.QStyle.State_Sunken
        super(HeaderProxyStyle, self).drawControl(
            element, option, painter, widget
        )


if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)

    w = QtWidgets.QTableView()
    # https://bugreports.qt.io/browse/PYSIDE-922
    w.horizontalHeader().setStyle(HeaderProxyStyle())

    model = QtGui.QStandardItemModel(4, 4)
    w.setModel(model)

    w.show()

    sys.exit(app.exec_())
eyllanesc
  • 235,170
  • 19
  • 170
  • 241