当前位置: 首页>>代码示例>>C++>>正文


C++ QListWidget::hasFocus方法代码示例

本文整理汇总了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();
}
开发者ID:luke147,项目名称:tvclipper,代码行数:45,代码来源:listitemdelegate.cpp


注:本文中的QListWidget::hasFocus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。