I am working with PyQt5. I want to show a sort indicator for my QTableWidget, so I did:
table = QTableWidget()
table.setSortingEnabled(True)
table.horizontalHeader().setSortIndicatorShown(True)
I prefer if the sort indicator was on the right of the table header so I added this
table.horizontalHeader().setStyleSheet('QHeaderView::down-arrow { subcontrol-position: center right}')
The problem is that when the indicator is on the right it is pretty much not visible. see below, on the left there is no arrow and on the right the arrow is pointing down.
If I add right: 10px to the stylesheet
table.horizontalHeader().setStyleSheet('QHeaderView::down-arrow { subcontrol-position: center right; right: 10px }')
I get this
When the arrow is on top I find it too small
Would anyone know how to make the sort indicator more visible (preferably on the right side)?
Working code:
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableWidget, \
QTableWidgetItem, QVBoxLayout, QWidget
from PyQt5.QtCore import QSize
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.setMinimumSize(QSize(300, 300))
table = QTableWidget()
table.setSortingEnabled(True)
table.horizontalHeader().setSortIndicatorShown(True)
table.horizontalHeader().setStyleSheet('QHeaderView::down-arrow { subcontrol-position: center right}')
table.setColumnCount(4)
table.setRowCount(4)
# Set table headers
table.setHorizontalHeaderLabels(["Header-1", "Header-2", "Header-3", "Header-4"])
# generate values
for i in range(4):
for j in range(4):
table.setItem(i, j, QTableWidgetItem(str(i) + ", " + str(j)))
# display table
self.layout = QVBoxLayout()
self.layout.addWidget(table)
widget = QWidget()
widget.setLayout(self.layout)
self.setCentralWidget(widget)
self.show()
# Create app object and execute app
app = QApplication(sys.argv)
mw = Window()
app.exec()