Results 1 to 2 of 2

Thread: Change color of only the first row in QML/Qt TableView

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Change color of only the first row in QML/Qt TableView

    I am using TableView of QtQuick.Controls 1.4
    This is the rowDelegate. I want to have just the first row of blue colour and rest of the rows (empty or non-empty) of green color.

    Qt Code:
    1. rowDelegate:
    2. Rectangle
    3. {
    4. border.width: 1
    5. height: 50
    6. width: 2000
    7.  
    8. color: {
    9. var item = mymodel.get( styleData.row )
    10.  
    11. if (item.index1 === "1")
    12. return "blue"
    13.  
    14. return "green"
    15.  
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 
    Now, my problem is that this code does colour the first row as blue but it also colours the empty rows as blue.

    What is the way to solve this problem?

    Screenshot from 2020-12-11 20-41-06.jpg

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    459
    Thanks
    10
    Thanked 61 Times in 59 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change color of only the first row in QML/Qt TableView

    Hi, probably item.index1 is not what you expect it to be. Use a debugger to check the value for the other rows.

    Ginsengelf

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

    TheIndependentAquarius (4th January 2021)

Similar Threads

  1. Replies: 0
    Last Post: 2nd December 2020, 17:06
  2. Replies: 4
    Last Post: 3rd July 2014, 15:52
  3. color specified cell in a tableview
    By poporacer in forum Newbie
    Replies: 1
    Last Post: 29th March 2011, 21:52
  4. Replies: 3
    Last Post: 22nd January 2010, 17:46
  5. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 23:25

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.