Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[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?

    1. what are the minimum functionality I have to give to my subclass for it to work properly?
    2. how could i get the cell to display rich text?

    Thank you so much!





  • 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.


Log in to reply