本文整理汇总了C++中ItemWidget::setHighlight方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemWidget::setHighlight方法的具体用法?C++ ItemWidget::setHighlight怎么用?C++ ItemWidget::setHighlight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemWidget
的用法示例。
在下文中一共展示了ItemWidget::setHighlight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paint
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
int row = index.row();
ItemWidget *w = m_cache[row];
if (w == NULL)
return;
const QRect &rect = option.rect;
bool isSelected = option.state & QStyle::State_Selected;
/* render background (selected, alternate, ...) */
QStyle *style = m_view->style();
style->drawControl(QStyle::CE_ItemViewItem, &option, painter, m_view);
/* render number */
if (m_showRowNumber) {
const QString num = QString::number(row);
QPalette::ColorRole role = isSelected ? QPalette::HighlightedText : QPalette::Text;
painter->save();
painter->setFont(m_rowNumberFont);
style->drawItemText(painter, rect.translated(m_hMargin / 2, m_vMargin), 0,
m_rowNumberPalette, true, num,
role);
painter->restore();
}
/* highlight search string */
w->setHighlight(m_re, m_foundFont, m_foundPalette);
/* text color for selected/unselected item */
QWidget *ww = w->widget();
if ( ww->property(propertySelectedItem) != isSelected ) {
ww->setProperty(propertySelectedItem, isSelected);
if ( !ww->property("CopyQ_no_style").toBool() ) {
ww->setStyle(style);
foreach (QWidget *child, ww->findChildren<QWidget *>())
child->setStyle(style);
ww->update();
}
}
}
示例2: paint
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
int row = index.row();
ItemWidget *w = m_cache[row];
if (w == NULL)
return;
const QRect &rect = option.rect;
/* render background (selected, alternate, ...) */
QStyle *style = m_parent->style();
style->drawControl(QStyle::CE_ItemViewItem, &option, painter);
QPalette::ColorRole role = option.state & QStyle::State_Selected ?
QPalette::HighlightedText : QPalette::Text;
/* render number */
QRect numRect(0, 0, 0, 0);
if (m_showNumber) {
QString num = QString::number(row) + " ";
painter->save();
painter->setFont(m_numberFont);
style->drawItemText(painter, rect.translated(4, 4), 0,
m_numberPalette, true, num,
role);
painter->restore();
numRect = style->itemTextRect( QFontMetrics(m_numberFont), rect, 0,
true, num );
}
/* highlight search string */
w->setHighlight(m_re, m_foundFont, m_foundPalette);
/* text color for selected/unselected item */
QPalette palette = w->widget()->palette();
palette.setColor( QPalette::Text, option.palette.color(role) );
w->widget()->setPalette(palette);
/* render widget */
w->widget()->show();
}