Multiple fonts in a QTableWidgetItem?
-
It's possible to do a setFont on a QTableWidgetItem, but is it also possible to have text with more than one font inside of a QTableWidgetItem?
-
Not out of the box.
You could provide a QItemDelegate that interprets the item value as some form of rich text, renders it however it wants in QItemDelegate::paint(), and ensures a suitable editor is provided by QItemDelegate::createEditor().
-
@ChrisW67 The problem I'm trying to solve is that I want to align the text in two adjacent cells. One has let's say 12 point font, and the other has 24 point. But I want their baseline to be the same. So I thought that in the 12 point cell I could add a single space character that is 24 point and that would align them.
Maybe what I need instead is an internal top margin. -
Have you tried having your model return
Qt::AlignLeft | Qt::AlignBaseline
for theQt::TextAlignmentRole
to see what happens? (No guarantees, but it might scratch the itch)You can also use a delegate to render plain text however you want. If the same delegate is used on the affected columns then it could position the text of both to have the baseline a consistent position relative to the bottom of the cell.