本文整理汇总了C++中QListWidget::hasFocus方法的典型用法代码示例。如果您正苦于以下问题:C++ QListWidget::hasFocus方法的具体用法?C++ QListWidget::hasFocus怎么用?C++ QListWidget::hasFocus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListWidget
的用法示例。
在下文中一共展示了QListWidget::hasFocus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paint
void ListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QListWidget *eventlist = (QListWidget*) this->parent();
bool isFocusedList = true;
if (eventlist)
isFocusedList = eventlist->hasFocus();
bool isSelectedItem = option.state & QStyle::State_Selected;
QString text = index.data(Qt::DisplayRole).toString();
text = getHtmlWithColours(text, isSelectedItem, isFocusedList);
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
QSize iconSize = icon.actualSize(QSize(option.rect.size().height() * 2, option.rect.size().height()));
QRect iconRect = QRect(option.rect.x() + EVENT_ITEM_ICON_MARGIN, option.rect.y() + EVENT_ITEM_ICON_MARGIN, iconSize.width(), iconSize.height());
QPixmap iconPixmap = icon.pixmap(iconSize);
QPoint textTopLeft = QPoint(iconRect.x() + iconSize.width() + EVENT_ITEM_ICON_MARGIN + EVENT_ITEM_TEXT_MARGIN, option.rect.y() + EVENT_ITEM_ICON_MARGIN + EVENT_ITEM_TEXT_MARGIN);
QSize textSize = QSize(option.rect.width() - textTopLeft.x(), option.rect.height() - textTopLeft.y());
QRect textRect = QRect(textTopLeft, textSize);
QTextDocument document;
document.setUndoRedoEnabled(false);
if (isSelectedItem)
{
const QPalette::ColorRole color = (isFocusedList) ? QPalette::Highlight : QPalette::Window;
painter->resetTransform();
painter->fillRect(option.rect, option.palette.color(color));
}
//painter->save();
//painter->restore();
painter->resetTransform();
document.setHtml(text);
painter->drawPixmap(iconRect, iconPixmap);
//painter->save();
//painter->restore();
painter->resetTransform();
painter->translate(textRect.topLeft());
painter->setRenderHint(QPainter::Antialiasing, true);
document.drawContents(painter);
//painter->save();
//painter->restore();
}