Greetings!
Currently I have the class below, which paints the lines of column 94 of a QTableView.
I need to get the values of each line of this column, to check which color it will paint in that row/column
{
if (index.column() == 94)
{
if (GetValueOfColumn94 <= 20)
painter->fillRect(option.rect, Qt::green);
else if (GetValueOfColumn94 >=21<=60)
painter->fillRect(option.rect, Qt::yellow);
if (GetValueOfColumn94 >=61<=100)
painter->fillRect(option.rect, Qt::red);
}
}
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() == 94)
{
if (GetValueOfColumn94 <= 20)
painter->fillRect(option.rect, Qt::green);
else if (GetValueOfColumn94 >=21<=60)
painter->fillRect(option.rect, Qt::yellow);
if (GetValueOfColumn94 >=61<=100)
painter->fillRect(option.rect, Qt::red);
}
return QItemDelegate::paint(painter, option, index);
}
To copy to clipboard, switch view to plain text mode
in code above, the "GetValueOfColumn94" is what i need. I've tried with this 2 methods below, but not work
index.sibling(index.row(),94).data().toInt();
index.model()->data(index.model()->index(index.row(),94),Qt::DisplayRole).toInt();
index.sibling(index.row(),94).data().toInt();
index.model()->data(index.model()->index(index.row(),94),Qt::DisplayRole).toInt();
To copy to clipboard, switch view to plain text mode
someone could help me?
Thanks!
Juliano
Greetings!
Currently I have the class below, which paints the lines of column 94 of a QTableView.
I need to get the values of each line of this column, to check which color it will paint in that row/column
{
if (index.column() == 94)
{
if (GetValueOfColumn94 <= 20)
painter->fillRect(option.rect, Qt::green);
else if (GetValueOfColumn94 >=21<=60)
painter->fillRect(option.rect, Qt::yellow);
if (GetValueOfColumn94 >=61<=100)
painter->fillRect(option.rect, Qt::red);
}
}
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() == 94)
{
if (GetValueOfColumn94 <= 20)
painter->fillRect(option.rect, Qt::green);
else if (GetValueOfColumn94 >=21<=60)
painter->fillRect(option.rect, Qt::yellow);
if (GetValueOfColumn94 >=61<=100)
painter->fillRect(option.rect, Qt::red);
}
return QItemDelegate::paint(painter, option, index);
}
To copy to clipboard, switch view to plain text mode
in code above, the "GetValueOfColumn94" is what i need. I've tried with this 2 methods below, but not work
index.sibling(index.row(),94).data().toInt();
index.model()->data(index.model()->index(index.row(),94),Qt::DisplayRole).toInt();
index.sibling(index.row(),94).data().toInt();
index.model()->data(index.model()->index(index.row(),94),Qt::DisplayRole).toInt();
To copy to clipboard, switch view to plain text mode
someone could help me?
Thanks!
Juliano
Added after 1 27 minutes:
Solved!
QVariant GetValueOfColumn94
= index.
model()->data
(index.
model()->index
(index.
row(),
94),Qt
::DisplayRole);
if (GetValueOfColumn94 == "Green")
painter
->fillRect
(option.
rect,
QColor(170,
216,
0));
else if (GetValueOfColumn94 == "Yellow")
painter
->fillRect
(option.
rect,
QColor(254,
251,
24));
if (GetValueOfColumn94 == "Red")
painter
->fillRect
(option.
rect,
QColor(255,
40,
0));
QVariant GetValueOfColumn94 = index.model()->data(index.model()->index(index.row(),94),Qt::DisplayRole);
if (GetValueOfColumn94 == "Green")
painter->fillRect(option.rect, QColor(170, 216, 0));
else if (GetValueOfColumn94 == "Yellow")
painter->fillRect(option.rect, QColor(254, 251, 24));
if (GetValueOfColumn94 == "Red")
painter->fillRect(option.rect, QColor(255, 40, 0));
To copy to clipboard, switch view to plain text mode
Thanks!
Juliano
Bookmarks