View Full Version : absolutely center text alignment in qtablewidgetitem that has an icon

4th April 2011, 19:48
I have a QTableWidget which contains cells which may or may not contain QIcons in them. When I align the texts of cells with icons in them, they are centered more right than cells without icons in them.


How do I make the text in cells with icons center so that they align with the entire cell, and not the text portion of the QTableWidgetItem?

I tried:

QTableWidgetItem::setTextAlignment(Qt::AlignAbsolu te | Qt:: AlignCenter)

I have read into similar threads describing the use of QItemDelegates when considering icon alignment, but does this method work for QTableWidgetItems via medelling with the Qt::DisplayRole portion of QItemDelegate or am I completely off?

4th April 2011, 20:41
Yes, you need a custom delegate. Compute the positions yourself and render the items (semi-)manually.