PDA

View Full Version : Change color of only the first row in QML/Qt TableView



TheIndependentAquarius
11th December 2020, 15:41
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.


rowDelegate:
Rectangle
{
border.width: 1
height: 50
width: 2000

color: {
var item = mymodel.get( styleData.row )

if (item.index1 === "1")
return "blue"

return "green"

}
}

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?

13582

Ginsengelf
17th December 2020, 10:38
Hi, probably item.index1 is not what you expect it to be. Use a debugger to check the value for the other rows.

Ginsengelf