Results 1 to 4 of 4

Thread: Set Table Cell Color based off Value

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

    Question Set Table Cell Color based off Value

    Good Day,

    My overall goal would be to have the table cell color change based off the current value.

    As I am still new to QT Designer I am currently just trying to change the color of an individual cell, but do not seem to be having any luck.

    Would anybody be able to point me in the direction of things I should be researching to accomplish this task?

    Thanks in advance,

    Sarol

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

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

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

    Sarol (12th May 2011)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    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.

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

    Sarol (12th May 2011)

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

    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, 18:56
  2. QTreeView cell as table
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 09:45
  3. Replies: 9
    Last Post: 21st June 2007, 10:27
  4. Table cell merge/join
    By larry104 in forum Qt Programming
    Replies: 6
    Last Post: 16th June 2006, 22:35
  5. Highlighting the border of cell in Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2006, 08: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.