QTableWidget different font in one cell
-
@AlexSmart Can you please explain what you mean?
-
@AlexSmart
Since a cell only displays a single text. (You could try putting in rich text/HTML, but I don't think it supports that?). Sounds to me like you would need aQStyledItemDelegate
to achieve the changed font. Or if you are lazy, and @VRonin doesn't see this,setCellWidget(QLabel*)
and do your formatting in the label, which does accept HTML. -
-
We have a regular expert contributor named @VRonin (though he doesn't seem to have been around lately). His signature includes "wanting to banish all uses of
setCellWidget()
. If you use it, he shouts at you ;-) -
Widgets use relatively quite a bit of resources (think of what they have to be able to do). It's all very well when you have a handful of widgets on a page. But when you put them into tables (
QTableWidget
has a "convenience" methodsetCellWidget()
) you are in danger of creating hundreds+ of them. Yet most of the time they really sit there just showing some text/bitmap/whatever, so most of the resource usage (memory, processing) is "wasted". It can for example become "slow" to show them all. Instead aQAbstractItemView
-derived object (includesQTableView
/QTableWidget
) can usesetItemDelegate()
on aQStyledItemDelegate
you write to set the display/editing of the items without needing the overhead of a fullQWidget
. If you had hundreds/thousands in a table this would be faster and use less resources. I didn't look to see whether/how easy it might be to emulate the mixed-font display supported by aQLabel
in aQStyledItemDelegate
: have a look/give it a go if you can, if you can't/you're lazy/you just want to see quickly what might be doable usesetCellWidget()
on aQLabel
you create.
-