I’m making a GUI in PyQt5 which has a QTableWidget. Is there some way to get rid of the gray selection of the previous selected cell after moving focus from this QTableWidget to another widget in the GUI?
Advertisement
Answer
You can use the palette to control the colour of the inactive selection. Setting it to transparent would seem the best solution, as it will also work with alternating row colours:
palette = self.table.palette() palette.setColor(QPalette.Inactive, QPalette.Highlight, Qt.transparent) self.table.setPalette(palette)
If you’re using Qt Designer, you can edit the table’s palette via the Property Editor. In the Edit Palette dialog, click the Show Details button at the top to display the extra columns for inactive/disabled colours. Then click on the cell for the Inactive Highlight colour role, and set the Alpha channel to zero.