本文整理汇总了C++中QStyle::itemPixmapRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QStyle::itemPixmapRect方法的具体用法?C++ QStyle::itemPixmapRect怎么用?C++ QStyle::itemPixmapRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStyle
的用法示例。
在下文中一共展示了QStyle::itemPixmapRect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paint
void AnnotatedItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
auto opt = option;
initStyleOption(&opt, index);
QStyle *style = QApplication::style();
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
QString annotation = index.data(m_annotationRole).toString();
if (!annotation.isEmpty()) {
int newlinePos = annotation.indexOf(QLatin1Char('\n'));
if (newlinePos != -1) {
// print first line with '...' at end
const QChar ellipsisChar(0x2026);
annotation = annotation.left(newlinePos) + ellipsisChar;
}
QPalette disabled(opt.palette);
disabled.setCurrentColorGroup(QPalette::Disabled);
painter->save();
painter->setPen(disabled.color(QPalette::WindowText));
static int extra = opt.fontMetrics.width(m_delimiter) + 10;
const QPixmap &pixmap = opt.icon.pixmap(opt.decorationSize);
const QRect &iconRect = style->itemPixmapRect(opt.rect, opt.decorationAlignment, pixmap);
const QRect &displayRect = style->itemTextRect(opt.fontMetrics, opt.rect,
opt.displayAlignment, true, index.data(Qt::DisplayRole).toString());
QRect annotationRect = style->itemTextRect(opt.fontMetrics, opt.rect,
opt.displayAlignment, true, annotation);
annotationRect.adjust(iconRect.width() + displayRect.width() + extra, 0,
iconRect.width() + displayRect.width() + extra, 0);
QApplication::style()->drawItemText(painter, annotationRect,
Qt::AlignLeft | Qt::AlignBottom, disabled, true, annotation);
painter->restore();
}
}
示例2: paint
void WidgetDiskItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItemV4 opt = *qstyleoption_cast<const QStyleOptionViewItemV4*>(&option);
bool selected = opt.state & QStyle::State_Selected;
QStyle* style = (opt.widget != NULL ? opt.widget->style() : QApplication::style());
QString text = index.data(Qt::DisplayRole).toString();
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
QPixmap pixmap = icon.pixmap(opt.decorationSize, (selected == true ? QIcon::Selected : QIcon::Normal));
int alignment = 0;
switch (opt.decorationPosition) {
case QStyleOptionViewItem::Left:
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
break;
case QStyleOptionViewItem::Right:
alignment |= Qt::AlignRight | Qt::AlignVCenter;
break;
case QStyleOptionViewItem::Top:
alignment |= Qt::AlignTop | Qt::AlignHCenter;
break;
case QStyleOptionViewItem::Bottom:
alignment |= Qt::AlignBottom | Qt::AlignHCenter;
break;
}
QRect icon_rect = style->itemPixmapRect(opt.rect.adjusted(adjust_dx, adjust_dy, -adjust_dx, -adjust_dy), alignment, pixmap);
style->drawItemPixmap(painter, icon_rect, opt.decorationAlignment, pixmap);
QRect free_rect;
switch (opt.decorationPosition) {
case QStyleOptionViewItem::Left:
free_rect = opt.rect.adjusted(icon_rect.width() + adjust_dx * 3, adjust_dy, -adjust_dx, -adjust_dy);
break;
case QStyleOptionViewItem::Right:
free_rect = opt.rect.adjusted(adjust_dx, adjust_dy, -icon_rect.width() - adjust_dx * 3, -adjust_dy);
break;
case QStyleOptionViewItem::Top:
free_rect = opt.rect.adjusted(adjust_dx, icon_rect.height() + adjust_dy * 3, -adjust_dx, -adjust_dy);
break;
case QStyleOptionViewItem::Bottom:
free_rect = opt.rect.adjusted(adjust_dx, adjust_dy, -adjust_dx, -icon_rect.height() - adjust_dy * 3);
break;
}
if (selected == true) {
int dr = qMax(adjust_dx, adjust_dy);
QRect text_rect = style->itemTextRect(opt.fontMetrics, free_rect, alignment, true, text);
QRect high_rect = text_rect.adjusted(-dr, -dr, dr, dr);
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
painter->setPen(opt.palette.highlight().color());
painter->setBrush(opt.palette.highlight());
painter->drawRoundedRect(high_rect, dr, dr);
painter->restore();
}
style->drawItemText(painter, free_rect, alignment, option.palette, true, text, (selected == true ? QPalette::HighlightedText : QPalette::WindowText));
}