void KisNodeDelegate::drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const { KisNodeViewColorScheme scm; const QRect rc = textRect(option, index) .adjusted(scm.textMargin(), 0, -scm.textMargin(), 0); QPen oldPen = p->pen(); const qreal oldOpacity = p->opacity(); // remember previous opacity p->setPen(option.palette.color(QPalette::Active,QPalette::Text )); if (!(option.state & QStyle::State_Enabled)) { p->setOpacity(0.55); } const QString text = index.data(Qt::DisplayRole).toString(); const QString elided = elidedText(p->fontMetrics(), rc.width(), Qt::ElideRight, text); p->drawText(rc, Qt::AlignLeft | Qt::AlignVCenter, elided); p->setPen(oldPen); // restore pen settings p->setOpacity(oldOpacity); }
void PrimitiveItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QAbstractItemModel *model = index.model(); Q_ASSERT(model); if (!model->parent(index).isValid()) { // if we ever want to change up the style a bit. //dc: QStyleOptionHeader headerOption; //dc: headerOption.state = option.state; //dc: headerOption.rect = option.rect; //dc: headerOption.palette = option.palette; //dc: d->view->style()->drawControl(QStyle::CE_HeaderSection, &dockOption, painter, d->view); QPen pen = painter->pen(); // this is a top-level item. QStyleOptionButton buttonOption; buttonOption.state = option.state; #ifdef Q_WS_MAC buttonOption.state |= QStyle::State_Raised; #endif buttonOption.state &= ~QStyle::State_HasFocus; buttonOption.rect = option.rect; buttonOption.palette = option.palette; buttonOption.features = QStyleOptionButton::None; d->view->style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter, d->view); QStyleOption branchOption; static const int i = 9; // ### hardcoded in qcommonstyle.cpp QRect r = option.rect; branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i); branchOption.palette = option.palette; branchOption.state = QStyle::State_Children; if (d->view->isExpanded(index)) { branchOption.state |= QStyle::State_Open; } else { painter->setPen(Qt::darkGray); } d->view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, d->view); // draw text QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height()); QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle, model->data(index, Qt::DisplayRole).toString()); d->view->style()->drawItemText(painter, textrect, Qt::AlignCenter, option.palette, d->view->isEnabled(), text); painter->setPen(pen); } else { QItemDelegate::paint(painter, option, index); } }
void PluginListWidgetItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (!index.isValid()) return; auto xOffset = m_checkBox->sizeHint().width(); xOffset += QApplication::style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing); painter->save(); QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0); auto contentsRect = QRect{m_pluginSelector->dependantLayoutValue(option.rect.left() + MARGIN + xOffset, option.rect.width() - MARGIN * 2 - xOffset, option.rect.width()), MARGIN + option.rect.top(), option.rect.width() - MARGIN * 2 - xOffset, option.rect.height() - MARGIN * 2}; auto lessHorizontalSpace = MARGIN * 2 + m_pushButton->sizeHint().width(); contentsRect.setWidth(contentsRect.width() - lessHorizontalSpace); if (option.state & QStyle::State_Selected) painter->setPen(option.palette.highlightedText().color()); if (m_pluginSelector->m_listView->layoutDirection() == Qt::RightToLeft) contentsRect.translate(lessHorizontalSpace, 0); { painter->save(); auto font = titleFont(option.font); auto fmTitle = QFontMetrics{font}; painter->setFont(font); painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignTop, fmTitle.elidedText(index.model()->data(index, Qt::DisplayRole).toString(), Qt::ElideRight, contentsRect.width())); painter->restore(); } painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignBottom, option.fontMetrics.elidedText(index.model()->data(index, PluginModel::CommentRole).toString(), Qt::ElideRight, contentsRect.width())); auto subfont = subtitleFont(option.font); auto fmSubtitle = QFontMetrics{subfont}; painter->setFont(subfont); painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignVCenter, fmSubtitle.elidedText(index.model()->data(index, PluginModel::NameRole).toString(), Qt::ElideRight, contentsRect.width())); painter->restore(); }
void PacmanSheetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QAbstractItemModel *model = index.model(); Q_ASSERT(model); if (model->hasChildren(index)) { // this is a top-level item. QStyleOptionButton buttonOption; buttonOption.state = option.state; buttonOption.state &= ~QStyle::State_HasFocus; buttonOption.rect = option.rect; buttonOption.palette = option.palette; buttonOption.features = QStyleOptionButton::None; buttonOption.fontMetrics = option.fontMetrics; buttonOption.iconSize = option.decorationSize; m_view->style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter, m_view); int i = 0; QRect r = option.rect; if (m_view->itemsExpandable()) { i = 9; QStyleOption branchOption; branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i); branchOption.palette = option.palette; branchOption.state = QStyle::State_Children; if (m_view->isExpanded(index)) branchOption.state |= QStyle::State_Open; m_view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, m_view); } int decorationSize_width = option.decorationSize.width(); QIcon icon = model->data(index, Qt::DecorationRole).value<QIcon>(); if (!icon.isNull()) { QRect iconrect = QRect(r.left() + i*2, r.top(),decorationSize_width, r.height()); m_view->style()->drawItemPixmap(painter,iconrect,Qt::AlignLeft,icon.pixmap(option.decorationSize)); } else decorationSize_width = 0; // draw text QRect textrect = QRect(r.left() + i*2 + decorationSize_width + 2, r.top(), r.width() - ((5*i)/2) - decorationSize_width - 2, r.height()); QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle,model->data(index, Qt::DisplayRole).toString()); m_view->style()->drawItemText(painter, textrect,Qt::AlignLeft|Qt::AlignVCenter, option.palette, m_view->isEnabled(), text); } else { QItemDelegate::paint(painter, option, index); } }
void QtElidingLabel::paintEvent(QPaintEvent* event) { QRect rect = contentsRect(); dirty_ = dirty_ || rect != lastRect_; if (dirty_) { lastRect_ = rect; int fontWidth = fontMetrics().width(fullText_); if (fontWidth > rect.width()) { QString elidedText(fontMetrics().elidedText(fullText_, Qt::ElideRight, rect.width(), Qt::TextShowMnemonic)); QLabel::setText(elidedText); } else { QLabel::setText(fullText_); } dirty_ = false; } QLabel::paintEvent(event); }
void KoDocumentSectionDelegate::drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QRect r = textRect(option, index).translated(option.rect.topLeft()); p->save(); { p->setClipRect(r); p->translate(r.left(), r.top()); QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? QPalette::Active : QPalette::Disabled; QPalette::ColorRole cr = (option.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text; p->setPen(option.palette.color(cg, cr)); if (index.data(Model::ActiveRole).toBool()) { QFont f = p->font(); f.setBold(!f.bold()); p->setFont(f); } const QString text = index.data(Qt::DisplayRole).toString(); const QString elided = elidedText(p->fontMetrics(), r.width(), Qt::ElideRight, text); p->drawText(d->margin, 0, r.width(), r.height(), Qt::AlignLeft | Qt::AlignTop, elided); } p->restore(); }
void TimeTrackingView::paintEvent( QPaintEvent* e ) { m_activeFieldRects.clear(); const int FieldHeight = m_cachedTotalsFieldRect.height(); QPainter painter( this ); // all attributes are determined in data(), we just paint the rects: for ( int row = 0; row < rowCount() - 1; ++row ) { for ( int column = 0; column < columnCount(); ++column ) { // get the rectangle of the field that will be drawn QRect fieldRect; const int y = row * FieldHeight; if ( column == columnCount() - 1 ) { // totals column fieldRect = QRect( width() - m_cachedTotalsFieldRect.width(), y, m_cachedTotalsFieldRect.width(), FieldHeight ); } else if ( column == 0 ) { // task column fieldRect = QRect( 0, y, taskColumnWidth(), FieldHeight ); } else if ( column > 0 ) { // a task fieldRect = QRect( width() - m_cachedTotalsFieldRect.width() - 8 * m_cachedDayFieldRect.width() + column * m_cachedDayFieldRect.width(), y, m_cachedDayFieldRect.width(), FieldHeight ); } // paint the field, if it is in the dirty region if( e->rect().contains( fieldRect ) ) { DataField field = m_defaultField; data( field, column, row ); int alignment = Qt::AlignRight | Qt::AlignVCenter; if ( row == 0 ) { alignment = Qt::AlignCenter | Qt::AlignVCenter; } else if ( column == 0 && row < rowCount() - 1 ) { alignment = Qt::AlignLeft | Qt::AlignVCenter; } if( column == 0 ) { // task column field.text = elidedText( field.text, field.font, fieldRect.width() - 2*Margin ); } if ( field.storeAsActive ) m_activeFieldRects << fieldRect; const QRect textRect = fieldRect.adjusted( Margin, Margin, -Margin, -Margin ); if ( field.hasHighlight ) { painter.setBrush( field.highlight ); painter.setPen( Qt::NoPen ); painter.drawRect( fieldRect ); } else { painter.setBrush( field.background ); painter.setPen( Qt::NoPen ); painter.drawRect( fieldRect ); } painter.setPen( palette().text().color() ); painter.setFont( field.font ); painter.drawText( textRect, alignment, field.text ); } } } // paint the tracking row const int top = ( rowCount() - 1 ) * FieldHeight; const QRect fieldRect( 0, top, width(), height() - top ); if ( e->rect().contains( fieldRect ) ) { DataField field = m_defaultField; data( field, 0, rowCount() - 1 ); painter.setBrush( field.background ); painter.setPen( Qt::NoPen ); painter.drawRect( fieldRect ); } }
void CustomLabel::paintEvent(QPaintEvent *pe) { if ((!text().isEmpty()) && (textFormat() == Qt::PlainText || (textFormat() == Qt::AutoText && !Qt::mightBeRichText(text())))) { QPainter painter(this); #ifndef DEBUG_CUSTOMLABEL QRectF lr = contentsRect(); lr.moveBottom(lr.bottom() - 1); // angry and dirty hack! QStyleOption opt; opt.initFrom(this); int align = QStyle::visualAlignment(text().isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight, alignment()); int flags = align | (!text().isRightToLeft() ? Qt::TextForceLeftToRight : Qt::TextForceRightToLeft); if (wordWrap()) flags |= Qt::TextWordWrap; switch (shadowType) { case NoShadow: flags |= TF_NOSHADOW; break; case DarkShadow: flags |= TF_DARKSHADOW; break; case LightShadow: flags |= TF_LIGHTSHADOW; break; default: break; } QString textToDraw = elidedText(); style()->drawItemText(&painter, lr.toRect(), flags, opt.palette, isEnabled(), textToDraw, QPalette::WindowText); #else // DEBUG_CUSTOMLABEL QTextDocument *doc = textDocument(); QAbstractTextDocumentLayout::PaintContext ctx = textDocumentPaintContext(doc); QString shadowKey; switch (shadowType) { case DarkShadow: shadowKey = GFX_TEXTSHADOWS; break; case LightShadow: shadowKey = GFX_NOTICEWIDGET; break; case NoShadow: default: break; } // magic numbers int dx = -2; int dy = -2; // adding margins dx += contentsMargins().left(); dy += contentsMargins().top(); # if 1 // for debug set 0 QGraphicsDropShadowEffect *shadow = qobject_cast<QGraphicsDropShadowEffect *>(GraphicsEffectsStorage::staticStorage(RSR_STORAGE_GRAPHICSEFFECTS)->getFirstEffect(shadowKey)); # else // debug shadow QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect; shadow->setColor(Qt::red); shadow->setOffset(1, 1); # endif if (shadow) { # if 0 // for "image method" set 1 QImage shadowedText(size(), QImage::Format_ARGB32_Premultiplied); # if defined(Q_WS_MAC) && !defined(__MAC_OS_X_NATIVE_FULLSCREEN) // TODO: fix that shadowedText.fill(Qt::red); // DUNNO WHY!!! # else shadowedText.fill(Qt::transparent); # endif QPainter tmpPainter(&shadowedText); tmpPainter.setRenderHint(QPainter::Antialiasing); tmpPainter.setRenderHint(QPainter::HighQualityAntialiasing); tmpPainter.setRenderHint(QPainter::TextAntialiasing); tmpPainter.setRenderHint(QPainter::SmoothPixmapTransform); tmpPainter.translate(dx, dy); doc->documentLayout()->draw(&tmpPainter, ctx); painter.drawImage(0, 0, shadowedText); # else // text method QPalette origPal = ctx.palette; ctx.palette.setColor(QPalette::Text, shadow->color()); // draw shadow painter.save(); painter.translate(dx + shadow->xOffset(), dy + shadow->yOffset()); doc->documentLayout()->draw(&painter, ctx); painter.restore(); ctx.palette = origPal; // draw text painter.save(); painter.translate(dx, dy); doc->documentLayout()->draw(&painter, ctx); painter.restore(); # endif // shadow method } else { painter.save(); painter.translate(dx, dy); doc->documentLayout()->draw(&painter, ctx); painter.restore(); } doc->deleteLater(); #endif // DEBUG_CUSTOMLABEL } else QLabel::paintEvent(pe); }
void DActionsListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { //QStyledItemDelegate::paint(painter, option, index); static const QPixmap deleteIconPixMap(":/icons/icons/delete-crosshair-icon.png"); static const QPixmap keepIconPixMap(":/icons/icons/keep-vgood-icon.png"); DItem item = index.data().value<DItem>(); DLS::FileProperty fprop = item.property; QString name; QString size; const QFontMetrics& metrics = option.fontMetrics; QRect rect_major = option.rect; rect_major.translate( 3, 3 ); //Need to trim... but hey!, translation alone serves us for now... QRect rect_minor = rect_major; const QPen originalPen = painter->pen(); if(option.state & QStyle::State_Selected) painter->fillRect( option.rect, QColor(250, 255, 180, 250)); else painter->fillRect( option.rect, QColor(255, 255, 255, 255) ); //aka WHITE QPen borderHighlightPen(originalPen); borderHighlightPen.setColor( QColor(Qt::red) ); painter->setPen( borderHighlightPen ); painter->drawRect( option.rect ); painter->setPen(originalPen); const QFont originalFont = painter->font(); QFont fnt = originalFont; fnt.setBold(true); if(item.isGroupHeader) { if(option.state & QStyle::State_Selected) { painter->fillRect( option.rect, QColor(130, 200, 130) ); groupHeaderSelected(index); } else painter->fillRect( option.rect, QColor(100, 100, 200, 100) ); name = item.header.topString(); int headerC = item.header.itemCount(); if(item.header.value()) size = fileSizeAsString( item.header.value() * headerC ) + " in total"; else size = "Not Available"; if(name.isEmpty()) return; const QString freeable( fileSizeAsString( (headerC - 1) * item.header.value()) + " can be freed" ); const QString fileCounts( QString::number( headerC ) + " Files :: " + QString::number( headerC - 1) + " duplicates" ); //qreal dx = rect_major.width() / 3.0; //painter->translate( dx, 0 ); painter->setFont( fnt ); painter->setPen( QColor(20, 40, 30) ); painter->drawText(rect_major, Qt::AlignLeft | Qt::AlignTop, name, &rect_minor); rect_minor.translate(0, rect_minor.height() ); painter->setPen( QColor(120, 50, 70) ); painter->drawText(rect_minor, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, size, &rect_major); painter->setFont( originalFont ); rect_major.translate( rect_major.width() + 10, 0); rect_major.setWidth( rect_major.width() + 600 ); painter->drawText(rect_major, Qt::AlignTop | Qt::AlignLeft, fileCounts, &rect_minor); rect_minor.translate( rect_minor.width() + 10, 0 ); rect_minor.setWidth( rect_minor.width() + 30 ); painter->drawText(rect_minor, Qt::AlignLeft | Qt::AlignTop, freeable); return; } name = fileNameAsString( fprop.getFilePath() ); size = fileSizeAsString( fprop.getSize() ); if(name.isEmpty()) return; const static QStaticText fileSizeStatic( "File Size: "); const static QStaticText fileNameStatic( "File Name: "); painter->drawStaticText(rect_major.topLeft(), fileNameStatic); rect_major.translate( metrics.width( fileNameStatic.text() ) , 0); rect_minor.translate( 0, metrics.height() ); painter->drawStaticText(rect_minor.topLeft(), fileSizeStatic); painter->setFont( fnt ); painter->setPen( QColor(20, 40, 30) ); QString elidedName = elidedText(metrics, (rect_major.width() - (rect_major.width() * 2.25/10)), Qt::ElideLeft, name ); painter->drawText(rect_major, Qt::AlignLeft | Qt::AlignTop, elidedName, &rect_minor); rect_minor.translate(0, rect_minor.height() ); painter->setPen( QColor(120, 50, 70) ); const static int k_align = Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap; painter->drawText(rect_minor, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, size, &rect_major); rect_major.setX( 200 ); rect_major.setWidth( rect_major.width() + 300 ); painter->setPen( QColor(Qt::red) ); QString keepingWeight("Keeping Weight: " + QString::number( item.keepingWeight ) ); QString deletionWeight("Deletion Weight " + QString::number( item.deletionWeight)); painter->drawText( rect_major, k_align, deletionWeight); rect_major.translate( 200, 0 ); painter->setPen( QColor(0, 220, 0) ); painter->drawText( rect_major, k_align, keepingWeight ); //drawPixMaps as necessary static const int dd = 20; int dx1 = option.rect.width() * 0.95; int dy1 = option.rect.height() * 0.2 + option.rect.top(); QRect checkedIconArea(dx1, dy1, dd, dd); if(item.isKeepChecked) painter->drawPixmap(checkedIconArea, keepIconPixMap); else if(item.isDeleteChecked) painter->drawPixmap(checkedIconArea, deleteIconPixMap); //restore original painter->setFont( originalFont ); painter->setPen( originalPen ); }
void SheetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QAbstractItemModel *model = index.model(); Q_ASSERT(model); if (!model->parent(index).isValid()) { // this is a top-level item. QStyleOptionButton buttonOption; buttonOption.state = option.state; #ifdef Q_OS_MAC buttonOption.state |= QStyle::State_Raised; #endif buttonOption.state &= ~QStyle::State_HasFocus; buttonOption.rect = option.rect; buttonOption.palette = option.palette; buttonOption.features = QStyleOptionButton::None; painter->save(); QColor buttonColor(230, 230, 230); QBrush buttonBrush = option.palette.button(); if (!buttonBrush.gradient() && buttonBrush.texture().isNull()) buttonColor = buttonBrush.color(); QColor outlineColor = buttonColor.darker(150); QColor highlightColor = buttonColor.lighter(130); // Only draw topline if the previous item is expanded QModelIndex previousIndex = model->index(index.row() - 1, index.column()); bool drawTopline = (index.row() > 0 && m_view->isExpanded(previousIndex)); int highlightOffset = drawTopline ? 1 : 0; QLinearGradient gradient(option.rect.topLeft(), option.rect.bottomLeft()); gradient.setColorAt(0, buttonColor.lighter(102)); gradient.setColorAt(1, buttonColor.darker(106)); painter->setPen(Qt::NoPen); painter->setBrush(gradient); painter->drawRect(option.rect); painter->setPen(highlightColor); painter->drawLine(option.rect.topLeft() + QPoint(0, highlightOffset), option.rect.topRight() + QPoint(0, highlightOffset)); painter->setPen(outlineColor); if (drawTopline) painter->drawLine(option.rect.topLeft(), option.rect.topRight()); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); painter->restore(); QStyleOption branchOption; static const int i = 9; // ### hardcoded in qcommonstyle.cpp QRect r = option.rect; branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i); branchOption.palette = option.palette; branchOption.state = QStyle::State_Children; if (m_view->isExpanded(index)) branchOption.state |= QStyle::State_Open; m_view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, m_view); // draw text QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height()); QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle, model->data(index, Qt::DisplayRole).toString()); m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter, option.palette, m_view->isEnabled(), text); } else { QItemDelegate::paint(painter, option, index); } }
void FileFrame::resizeEvent(QResizeEvent *event) { auto fm = ui->nameLabel->fontMetrics(); ui->nameLabel->setText(fm.elidedText(file_name_, Qt::ElideRight, ui->nameLabel->width())); }
void lmcUserTreeWidgetDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { painter->save(); QPalette palette = QApplication::palette(); QRect itemRect = option.rect; lmcUserTreeWidgetItem* pItem = static_cast<lmcUserTreeWidgetItem*>(index.internalPointer()); lmcUserTreeWidget* pTreeWidget = (lmcUserTreeWidget*)pItem->treeWidget(); QString type = pItem->data(0, TypeRole).toString(); QString name = pItem->data(0, Qt::DisplayRole).toString(); int padding = 2; if(type == "Group") { // fill the entire item area with window background color (usually white) painter->fillRect(itemRect, palette.window()); // Fill the background of the item with highlight color, and draw a border with a darker shade QColor fillColor = palette.color(QPalette::Highlight); QColor borderColor = fillColor.darker(130); painter->setPen(QPen(borderColor)); painter->setBrush(QBrush(fillColor)); itemRect.adjust(1, 1, -2, -1); painter->drawRect(itemRect); // Draw checkbox if needed QRect checkBoxRect = pItem->checkBoxRect(itemRect); if(pTreeWidget->checkable()) drawCheckBox(painter, palette, checkBoxRect, pItem->checkState(0)); // Draw the expand/collapse arrow painter->setBrush(QBrush(palette.color(QPalette::HighlightedText))); painter->setPen(QPen(palette.color(QPalette::HighlightedText))); QPoint points[3]; if(option.state.testFlag(QStyle::State_Children) && option.state.testFlag(QStyle::State_Open)) { points[0] = QPoint(checkBoxRect.right() + 4, itemRect.top() + ((itemRect.height() - 4) / 2)); points[1] = QPoint(checkBoxRect.right() + 12, itemRect.top() + ((itemRect.height() - 4) / 2)); points[2] = QPoint(checkBoxRect.right() + 8, itemRect.top() + ((itemRect.height() - 4) / 2) + 4); } else { points[0] = QPoint(checkBoxRect.right() + 6, itemRect.top() + ((itemRect.height() - 7) / 2)); points[1] = QPoint(checkBoxRect.right() + 10, itemRect.top() + ((itemRect.height() - 7) / 2) + 4); points[2] = QPoint(checkBoxRect.right() + 6, itemRect.top() + ((itemRect.height() - 7) / 2) + 8); } painter->drawPolygon(points, 3); // Draw the text QFont font = painter->font(); font.setBold(true); painter->setFont(font); int textFlags = Qt::AlignLeft | Qt::AlignVCenter; // Leave a padding of 5px on left and right int leftPad = checkBoxRect.width() > 0 ? checkBoxRect.right() + 16 : 16; QRect textRect = itemRect.adjusted(leftPad, padding, -5, -padding); painter->setPen(QPen(palette.color(QPalette::HighlightedText))); QString text = elidedText(painter->fontMetrics(), textRect.width(), Qt::ElideRight, name); painter->drawText(textRect, textFlags, text); } else if(type == "User") { QColor fillColor, borderColor; if(index.row() % 2 == 1) borderColor = fillColor = palette.color(QPalette::AlternateBase); else borderColor = fillColor = palette.color(QPalette::Base); if(option.state.testFlag(QStyle::State_Active) && option.state.testFlag(QStyle::State_Enabled) && option.state.testFlag(QStyle::State_Selected)) borderColor = palette.color(QPalette::Shadow); painter->setPen(QPen(borderColor)); painter->setBrush(QBrush(fillColor)); itemRect.adjust(1, 0, -2, -1); painter->drawRect(itemRect); // Draw checkbox if needed QRect checkBoxRect = pItem->checkBoxRect(itemRect); if(pTreeWidget->checkable()) drawCheckBox(painter, palette, checkBoxRect, pItem->checkState(0)); // Draw the status image QPixmap statusImage = pItem->icon(0).pixmap(QSize(16, 16)); int leftPad = checkBoxRect.width() > 0 ? checkBoxRect.right() + 5 : 5; QRect statusRect = itemRect.adjusted(leftPad, padding, 0, 0); statusRect.setSize(statusImage.size()); painter->drawPixmap(statusRect, statusImage); // Draw the avatar image QRect avatarRect = itemRect.adjusted(itemRect.width(), padding, 0, 0); if(pTreeWidget->view() == ULV_Detailed) { QVariant avatar = pItem->data(0, AvatarRole); if(!avatar.isNull()) { QPixmap avatarImage = ((QIcon)pItem->data(0, AvatarRole).value<QIcon>()).pixmap(32, 32); avatarRect.setLeft(avatarRect.right() - avatarImage.width() - padding); avatarRect.setSize(avatarImage.size()); painter->drawPixmap(avatarRect, avatarImage); } } // Draw the text painter->setPen(QPen(palette.color(QPalette::WindowText))); int textFlags = Qt::AlignLeft; textFlags |= (pTreeWidget->view() == ULV_Detailed ? Qt::AlignTop : Qt::AlignVCenter); // Leave a padding of 5px on left and right QRect textRect = itemRect.adjusted(statusRect.right() + 5, padding, -(5 + avatarRect.width() + padding), -padding); QString text = elidedText(painter->fontMetrics(), textRect.width(), Qt::ElideRight, name); painter->drawText(textRect, textFlags, text); // Draw sub text if(pTreeWidget->view() == ULV_Detailed) { QVariant note = pItem->data(0, SubtextRole); if(!note.isNull()) { QString userNote = note.toString(); painter->setPen(QPen(GRAY_TEXT_COLOR)); textFlags = Qt::AlignLeft | Qt::AlignBottom; text = elidedText(painter->fontMetrics(), textRect.width(), Qt::ElideRight, userNote); painter->drawText(textRect, textFlags, text); } } } painter->restore(); }