void NoFocusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem itemOption(option); if (itemOption.state & QStyle::State_HasFocus) { itemOption.state = itemOption.state ^ QStyle::State_HasFocus; } QStyledItemDelegate::paint(painter, itemOption, index); }
/* * Reimplemented the virtual function QStyledItemDelegate::paint() */ void NoFocusFrameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem itemOption(option); // remove the focus state if (itemOption.state & QStyle::State_HasFocus) { itemOption.state ^= QStyle::State_HasFocus; } QStyledItemDelegate::paint(painter, itemOption, index); }
void FNoFocusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem itemOption(option); if (itemOption.state & QStyle::State_HasFocus) { QPen penVal(Qt::white); penVal.setWidth(0); painter->setPen (penVal); } QStyledItemDelegate::paint(painter, itemOption, index); }
void CMyDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { QStyleOptionViewItemV4 itemOption(option); initStyleOption(&itemOption, index); itemOption.rect.adjust(10, 0, 0, 0); // Make the item rectangle 10 pixels smaller from the left side. // Draw your item content. QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &itemOption, painter, nullptr); // And now you can draw a bottom border. //painter->setPen(Qt::cyan); QPen pen = painter->pen(); pen.setColor(Qt::white); pen.setWidth(1); painter->setPen(pen); painter->drawLine(itemOption.rect.bottomLeft(), itemOption.rect.bottomRight()); }
void NoFocusDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const { QStyleOptionViewItem itemOption(option); if (itemOption.state & QStyle::State_HasFocus) itemOption.state = itemOption.state ^ QStyle::State_HasFocus; if(index.isValid()) { medAbstractDatabaseItem *item = NULL; if(QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(m_view->model())) item = static_cast<medAbstractDatabaseItem *>(proxy->mapToSource(index).internalPointer()); else if (dynamic_cast<QAbstractItemModel *>(m_view->model())) item = static_cast<medAbstractDatabaseItem *>(index.internalPointer()); if(item) { if(index.column()>0) { QPen pen; pen.setColor(QColor("#505050")); painter->setPen(pen); painter->drawLine(option.rect.x(), option.rect.y(), option.rect.x(), (option.rect.y()+option.rect.height())); } if (m_indexes.contains(item->dataIndex())) // items that failed to open will have a pinkish background painter->fillRect(option.rect, QColor("#FF3333")); medAbstractDbController * dbc = medDataManager::instance()->controllerForDataSource(item->dataIndex().dataSourceId()); if ( dbc ) { if(!dbc->isPersistent()) { itemOption.font.setItalic(true); } } } } QStyledItemDelegate::paint(painter, itemOption, index); }
void SongListItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { LOG_VERBOSE(__FUNCTION_NAME__); if(index.column()!=3) { #if 0 QStyleOptionViewItem itemOption(option); if(itemOption.state & QStyle::State_HasFocus) itemOption.state = itemOption.state ^ QStyle::State_HasFocus; QStyledItemDelegate::paint(painter,itemOption,index); QPen oldPen = painter->pen(); painter->setPen(pen); //painter->drawLine(option.rect.topRight(),option.rect.bottomRight()); painter->drawLine(itemOption.rect.bottomLeft(),itemOption.rect.bottomRight()); painter->setPen(oldPen); #else QItemDelegate::paint(painter,option,index); #endif return; } const QAbstractItemModel * model=index.model(); QVariant var=model->data(index,Qt::CheckStateRole); if(var.isNull()) var=false; const QPixmap & star=var.toBool()? favouritePixmap:notFavouritePixmap; int width=star.width(); int height=star.height(); QRect rect=option.rect; int x=rect.x()+rect.width()/2-width/2; int y=rect.y()+rect.height()/2-height/2; painter->drawPixmap(x,y,star); //QItemDelegate::paint(painter,option,index); }
void SchedulerCellDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 viewOption = option; painter->save(); QBrush brush = viewOption.backgroundBrush; QColor textColor = Qt::black; QRect rect = viewOption.rect; QString textCell = index.model()->data(index, SchedulerTableModel::WishDayRole).toString(); if (textCell == "RR") { brush = QBrush(Qt::lightGray); } else if (textCell == "XX") { textColor = Qt::white; brush = QBrush(Qt::black); // TODO: градиент как скрине // QLinearGradient gradient(rect.topLeft(), rect.bottomRight()); // gradient.setSpread(QGradient::RepeatSpread); // gradient.setColorAt(0, Qt::black); // gradient.setColorAt(1, Qt::white); // brush = QBrush(gradient); } else if (textCell == "DD") { brush = QBrush(Qt::yellow); rect.setWidth(rect.width() / 2); } else if (textCell == "NN") { brush = QBrush(Qt::yellow); rect.setX(rect.x() + rect.width() / 2); } painter->fillRect(rect, brush); DayKind day = index.model()->data(index, SchedulerTableModel::DayKindRole).value<DayKind>(); if (day != DayKind::NONE) { QImage dayImage = index.model()->data(index, SchedulerTableModel::DayImageKindRole).value<QImage>(); QRect rect = option.rect; // Отступ иконки в ячейке auto indent = 4; auto size = qMin(rect.size().width(), rect.size().height()) - indent * 2; if (!dayImage.isNull()) { dayImage = dayImage.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation); } if (isDay(day)) { painter->drawImage(rect.x() + indent, rect.y() + indent, dayImage); } else if (isNight(day)) { painter->drawImage(rect.x() + size + indent + indent * 2, rect.y() + indent, dayImage); } } // Если ячейка входит в LongRests ячейки, подрисуем снизу линию, подчеркивая ячейку const auto schedulerTableModel = dynamic_cast <const SchedulerTableModel*> (index.model()); if (schedulerTableModel && schedulerTableModel->columnInLongRests(index)) { painter->setPen(Qt::NoPen); painter->setBrush(QColor(255, 128, 0)); const auto heightLine = 4; auto rect = viewOption.rect; rect.setY(rect.y() + rect.height() - heightLine); rect.setHeight(heightLine); painter->drawRect(rect); } painter->restore(); // Цвет выделения полупрозрачный, чтобы были видно что в ячейке QStyleOptionViewItem itemOption(option); initStyleOption(&itemOption, index); if (itemOption.state & QStyle::State_Selected) { auto color = itemOption.palette.color(QPalette::Highlight); color.setAlpha(180); itemOption.palette.setColor(QPalette::Highlight, color); } // Здесь дорисовываются стандартные вещи вроде текста, которые берутся из модели QStyledItemDelegate::paint(painter, itemOption, index); }
void PositionLabelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem itemOption(option); itemOption.state = itemOption.state & ~QStyle::State_HasFocus; QItemDelegate::paint(painter,itemOption,index); }