tags:

views:

51

answers:

1

Hello im trying to programmatic select and change the background color of all the columns of QStandardItemModel
i have this that paint me only the first column out of 5 that the row contains

// getting the rows
QStandardItem* standardItem = m_model->item(i);
//set the color i like all the row to be painted
standardItem->setBackground(QBrush(QColor(255,0,0)));
+1  A: 

Try this..

for(int i = 0; i<rowCount; ++i)
{
   for(int j = 0; j<columnCount; ++j)
       {
            m_model->item(i,j)->setBackground(QBrush(QColor(255,0,0)));
       }
}

This isn't tested.. check it out..

liaK
thanks for the not tested warning..that's all fine and dandy for a table layout, but QStandardItemModel doesn't follow that fashion, and so the colloumnCount() can change based on the current row...
ianmac45
@ ianmac45, I dint mean to call the function columCount(). He specified the number of columns and so i used the variable named columnCount. Of course, you have to know the column count before the usage of the above snippet. Correct me, if i misunderstood your comment.
liaK
@ liak, ahh, i didn't notice that you used variables instead of the methods..but, what i said still applies to the row count, since there very well can be only one top level index, and it won't, by default, travel into the lower levels...but, either way, you did say it wasn't tested, and i was just explaining what i saw..
ianmac45
is there any why to know the column count ? whit out setting it hard coded ?
@ ianmac45, Yeah ok, but i dint go for index based traversal isn't? I used item based. I think you can traverse through items if you know the row and column count. Correct me if am wrong..
liaK
@user63898, are you sure about the row count?? I mean whether you know the row count of your standard item model??
liaK