I have a QTableWidget in which some of the QTableWidgetItem's contain a single QIcon (not a button, not clickable, just an image). Can anybody advise me on how to center the icon? I am providing below some sample code which correctly displays the icon, but fails to center it (setTextAlignment seems to work for the items that contain text but apparently not for icons).
status_item = QtGui.QTableWidgetItem()
status_icon = QtGui.QIcon()
status_icon.addPixmap(QtGui.QPixmap(icon_file), QtGui.QIcon.Normal, QtGui.QIcon.Off)
status_item.setIcon(status_icon)
self.ServiceTableWidget.setItem(row, 0, status_item)
self.ServiceTableWidget.item(row, 0).setTextAlignment(QtCore.Qt.AlignHCenter) #not working
I have also tried using the QIcon.paint() method, which did not work, although I may be implementing it incorrectly:
status_icon.paint(QtGui.QPainter(), QtCore.QRect(), QtCore.Qt.AlignCenter)
Thanks in advance!