0
votes

Problem

I'm using QTableWidget(Item) for presentation of some data. For that i need to italicize or set bold some parts of text. Problem: I don't want to italicize the whole cell/box, just parts of text in a cell.

Ideas

: Using the QTableWidgetItem refering to the correspondent cell and trying to modify the style (e.g. setFont(font)). But this operations always seem to alter the whole cell?

I also found this which doesn't help me for my QTableWidget problem.

Wanted

: To Have a QTableWidget with e.g. 2 rows and collumns containing cells like:

Exa mple Cell Text

(Nice Notation like Exa<b>mple</b> Cell <i>Text</i> is only a secondary aspect)

Note: Example should be one word.

1
it seems the generic QStyledItemDelegate QTableWidget/QTableView is using does not support rich text. We had similar requirement and implemented a custom QStyledItemDelegate to support rich text.Martian Puss
Hint for implementing custom delegates. Use qt-project.org/doc/qt-4.8/qtextdocument.html#drawContentsDmitry Sazonov
Why do you said "I also found this which doesn't help me for my QTableWidget problem" ? Instead this one seems to be a solution if you don't want reimplement a QStyledItemDelegate.Salvatore Avanzo

1 Answers

0
votes

Solved

I didn't see the wood for the trees. Thanks to Salvatore Avanzo, he is totally right.

All Item Widget classes provide functionality to render/paint something custom in each cell.

QTableWidget provides setCellWidget(.. QWidget..); QListWidget and QTreeWidget provide setItemWidget(..QWidget..). Therefore you can use any Subclass of QWidget (base of all ui objects) to paint something custom. For my aim i needed the capability to set a custom partially emphasized/italicized text. The Refering Subclass of QWidget for painting texts is QLabel (It itself is also a subclass of QPainDevice). A QWidget/Subclass of QWidget is drawed when paintEvent(..) is invoked (QLabel reimplemented that). QLabel also supports RichText functionality (flag is used by default), e.g. you can use <b>foo</b> to get foo.

So that's perfectly fits my problem and i will now use this solution.

Forecast for better structured solution

The unattractive aspect of the above mentioned solution is, that design and data get totally mixed. Editing Text in a QLabel is possible if you set the refering Interaction tags. But then you always need to use QLabel to get the text. When additionally setting an QTableWidgetItem in the Cell which also uses QLabel, they overlay ugly. So one could use QTableView. Here is a link.