Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Subclassing QTableWidgetItem
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Subclassing QTableWidgetItem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcos Modenesi
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Marcos Modenesi
        wrote on last edited by
        #3

        Hi, thank you, this was what I finally did.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          You're welcome.
          If your issue is solved mark thread as solved by editing first post title.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved