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. How to change the text color in QTableView
Qt 6.11 is out! See what's new in the release blog

How to change the text color in QTableView

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 22.3k 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hi All

    I want to change the color of the text in some cells in QTableView.
    How to do this?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Check QItemDelegate::drawDisplay.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Rajveer, are you using a QTableView this time, or are you really using a QTableModel as you were in your last questions?

        In the latter case, you should check out setting the Qt::ForeGroundRole on the cell you want to color.
        @
        QTableWidgetItem* myItem; //set it to the item you want to manipulate

        myItem->setForeground(QColor::fromRgb(255,0,0)); //make this item red.
        @

        If you really have your own model, then you need to return this color as a variant from your data() method, but I doubt you are doing that.

        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