Results 1 to 5 of 5

Thread: TableView - Change background color if row have specific value

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Jun 2013
    Location
    Dresden - Germany
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: TableView - Change background color if row have specific value

    Hi again,

    it's also possible. Read the value not from styleData.value (content of the current cell and maybe a name not a number), but from the model directly. Because itemDelegate is delegate for every single cell this is working when you get the value from the model itself with the help of styleData.row.

    To be honest: it's a bit strange and counter intuitive, maybe it's a bug that you get a ReferenceError when you try to use the role Name in the rowDelegate (which is acting also a bit strange, as far as I've seen, while playing around with it.)

    Here is a working example:

    Qt Code:
    1. TableView {
    2. id: table
    3. anchors.fill: parent
    4. model: testModel
    5. TableViewColumn {role: "name"; title: "Name"; width: 75}
    6. TableViewColumn {role: "timeToReply"; title: "Reply timings"; width: 100}
    7. itemDelegate: Text {
    8. anchors.verticalCenter: parent.verticalCenter
    9. color: testModel.get(styleData.row).timeToReply > 15 ? "red" : "black"
    10. text: styleData.value
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    AlphaX2

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

    updaterr (3rd July 2014)

Similar Threads

  1. Setting the background color of a header in TableView
    By sunilqt in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2013, 13:06
  2. Replies: 6
    Last Post: 27th September 2012, 23:44
  3. Replies: 1
    Last Post: 17th August 2010, 16:17
  4. how to change QTextEdit background color ?
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 22:05
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

Tags for this Thread

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.