PDA

View Full Version : QTableView and reimplement data



estanisgeyer
5th May 2008, 20:33
Hi,

I have a QTableView and set model QSqlQueryModel. I reimplement the function virtual data( ) and is functioning properly. The problem is that the first line is never applied what determines the method. How can I fix it?



QVariant ChequesRecModel::data(const QModelIndex &idx, int role) const
{
QVariant v = QSqlQueryModel::data(idx, role);

if ((idx.row()) && (role == Qt::BackgroundRole) &&
(index(idx.row(), 9, idx.parent()).data().toInt() == 0))
{
return QVariant(QColor(Qt::yellow));
}

return (v);

}


Thanks,

Marcelo E. Geyer
Brazil/RS

wysota
6th May 2008, 06:46
What do you mean it is never applied? What exactly do you want to achieve?

estanisgeyer
6th May 2008, 14:19
Hi,

See the image below. All lines of the result returned to the QTableView should be the color yellow, but he insists not paint the first line, regardless of my SQL, if order in one way or another.

Thanks,

Marcelo E. Geyer

mazurekwrc
6th May 2008, 14:38
idx.row() return 0 in


if ((idx.row()) && (role == Qt::BackgroundRole) &&
(index(idx.row(), 9, idx.parent()).data().toInt() == 0))

for the first row so I think this is a problem

estanisgeyer
7th May 2008, 13:55
Thanks,

My solution:



if ((idx.row() + 1) && (role == Qt::BackgroundRole) &&
(index(idx.row(), 9, idx.parent()).data().toInt() == 0))

wysota
7th May 2008, 17:26
(idx.row() + 1) is always true... unless the index is invalid, but there is a dedicated method to check that.

estanisgeyer
7th May 2008, 18:18
Yes, you are right, which both took this bit of code, giving me the result I want.



if ((role == Qt::BackgroundRole) &&
(index(idx.row(), 9, idx.parent()).data().toInt() == 0))


Thanks again,

Marcelo E. Geyer