[SOLVED] Subclassing QTableWidgetItem
-
I have a QTableWidget and I'd like it to show formatted text (bold, two or more text colors in the same cell). One of the solutions I thought of was setting a custom item prototype, subclassing QTableWidgetItem.
In the book "C++ Gui programming with Qt", in the spreadsheet example, the class Cell (derived from QTableWidgetItem) implements these functions:
@
QTableWidgetItem *clone() // used each time the table needs to create an item
void setData(int role, const QVariant &value) // to put data inside the item
QVariant data(int role) const // to retrieve data
void setFormula(const QString &formula) // this is customized functionality
etc..
@My question is:
0) do you think subclassing QTableWidgetitem is a good solution for displaying rich text?- what are the minimum functionality I have to give to my subclass for it to work properly?
- how could i get the cell to display rich text?
Thank you so much!
-
Hi. You can use "delegates":https://qt-project.org/doc/qt-4.8/qstyleditemdelegate.html for that.
some examples:
"rich-text-in-a-table":http://www.qtforum.org/article/15374/rich-text-in-a-table-help.html -
Hi, thank you, this was what I finally did.
-
You're welcome.
If your issue is solved mark thread as solved by editing first post title.