Results 1 to 4 of 4

Thread: Set Table Cell Color based off Value

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Set Table Cell Color based off Value

    void QTableWidgetItem::setData ( int role, const QVariant & value ) and look at doc for explanation of roles (Qt::ItemDataRole).

  2. The following user says thank you to m.p for this useful post:

    Sarol (12th May 2011)

  3. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Set Table Cell Color based off Value

    You cannot change the colour of individual cell contents from Designer.

    The colour of cell content in a QTableView is driven by data returned from the model (with the default delegate). You want your underlying model to return a value in the Qt::ForegroundRole or Qt::BackgroundRole that is based on the value of the cell. Look into the the model/view examples and docs.

    You could also address this with a custom delegate attached to the view if it is not appropriate/possible that the model return colour information globally.

  4. The following user says thank you to ChrisW67 for this useful post:

    Sarol (12th May 2011)

  5. #3
    Join Date
    May 2011
    Posts
    14
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    5

    Default Re: Set Table Cell Color based off Value

    m.p and ChrisW67,

    Thank you for giving me some direction on this matter. I have not worked with the Qt::ForegroundRole or Qt::BackgroundRole yet, but at least its a starting place to research this.

    Thanks again,

    Sarol

Similar Threads

  1. Replies: 1
    Last Post: 7th December 2009, 19:56
  2. QTreeView cell as table
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 10:45
  3. Replies: 9
    Last Post: 21st June 2007, 11:27
  4. Table cell merge/join
    By larry104 in forum Qt Programming
    Replies: 6
    Last Post: 16th June 2006, 23:35
  5. Highlighting the border of cell in Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2006, 09:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.