/
friendlyperch
/
QGrid
Обзор
Документация
Войти
/
friendlyperch
/
QGrid
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev-ver1
examples/GridExample/StatusCellRenderer.cpp
51 строка
1 KB
okuntsev
cell render
15 янв 2026, 13:16
15 янв 2026, 13:16
6be0fbd
Код
Авторство
О чём код?
#include "StatusCellRenderer.h" #include <QApplication> #include <QStyle> void StatusCellRenderer::paint(QPainter *painter, const QStyleOptionViewItem &option, const QVariant &value) const { QStyleOptionViewItem opt = option; opt.text = QString(); opt.icon = QIcon(); opt.features = QStyleOptionViewItem::None; QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter); QString status = value.toString(); QColor backgroundColor; QColor textColor; if (status == "Active") { backgroundColor = QColor(200, 255, 200); textColor = QColor(0, 100, 0); } else if (status == "Inactive") { backgroundColor = QColor(255, 200, 200); textColor = QColor(150, 0, 0); } else if (status == "Pending") { backgroundColor = QColor(255, 255, 200); textColor = QColor(150, 150, 0); } else { backgroundColor = QColor(240, 240, 240); textColor = QColor(100, 100, 100); } QRect rect = option.rect; rect.adjust(2, 2, -2, -2); painter->save(); painter->setRenderHint(QPainter::Antialiasing); painter->setBrush(backgroundColor); painter->setPen(QPen(textColor, 1)); painter->drawRoundedRect(rect, 4, 4); painter->setPen(textColor); painter->drawText(rect, Qt::AlignCenter, status); painter->restore(); }