Reputation: 23
I have a QTableView with icons and these icons by default display aligned to the left while I want to align them to the center. From the Qt Documentation the alignment only occurs for the TextAlignment under Qt.role only which has the role of Qt.DisplayRole().
How can the alingment be set to center for icons which have Qt.DecorationRole().
Upvotes: 1
Views: 1158
Reputation: 243975
One possible solution is to use a delegate:
class IconDelegate(QtWidgets.QStyledItemDelegate):
def initStyleOption(self, option, index):
super().initStyleOption(option, index)
option.decorationSize = option.rect.size()
delegate = IconDelegate(tableview)
tableview.setItemDelegate(delegate)
Upvotes: 1