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


C++ QStyle::inherits方法代码示例

本文整理汇总了C++中QStyle::inherits方法的典型用法代码示例。如果您正苦于以下问题:C++ QStyle::inherits方法的具体用法?C++ QStyle::inherits怎么用?C++ QStyle::inherits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QStyle的用法示例。


在下文中一共展示了QStyle::inherits方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: paint

void SidebarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QBrush backBrush;
    QColor foreColor;
    bool disabled = false;
    bool hover = false;
    if (!(option.state & QStyle::State_Enabled)) {
        backBrush = option.palette.brush(QPalette::Disabled, QPalette::Base);
        foreColor = option.palette.color(QPalette::Disabled, QPalette::Text);
        disabled = true;
    } else if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) {
        backBrush = option.palette.brush(QPalette::Highlight);
        foreColor = option.palette.color(QPalette::HighlightedText);
    } else if (option.state & QStyle::State_MouseOver) {
        backBrush = option.palette.color(QPalette::Highlight).light(115);
        foreColor = option.palette.color(QPalette::HighlightedText);
        hover = true;
    } else { /*if ( option.state & QStyle::State_Enabled )*/
        backBrush = option.palette.brush(QPalette::Base);
        foreColor = option.palette.color(QPalette::Text);
    }
    QStyle *style = QApplication::style();
    QStyleOptionViewItemV4 opt(option);
    // KStyle provides an "hover highlight" effect for free;
    // but we want that for non-KStyle-based styles too
    if (!style->inherits("KStyle") && hover) {
        Qt::BrushStyle bs = opt.backgroundBrush.style();
        if (bs > Qt::NoBrush && bs < Qt::TexturePattern)
            opt.backgroundBrush = opt.backgroundBrush.color().light(115);
        else
            opt.backgroundBrush = backBrush;
    }
    painter->save();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, 0);
    painter->restore();
    QIcon icon = index.data(Qt::DecorationRole).value< QIcon >();
    if (!icon.isNull()) {
        QPoint iconpos(
            (option.rect.width() - option.decorationSize.width()) / 2,
            ITEM_MARGIN_TOP
        );
        iconpos += option.rect.topLeft();
        QIcon::Mode iconmode = disabled ? QIcon::Disabled : QIcon::Normal;
        painter->drawPixmap(iconpos, icon.pixmap(option.decorationSize, iconmode));
    }

    if (m_showText) {
        QString text = index.data(Qt::DisplayRole).toString();
        QRect fontBoundaries = QFontMetrics(option.font).boundingRect(text);
        fontBoundaries.setWidth(fontBoundaries.width() + ITEM_PADDING);
        QPoint textPos(
            ITEM_MARGIN_LEFT + (option.rect.width() - ITEM_MARGIN_LEFT - ITEM_MARGIN_RIGHT - fontBoundaries.width()) / 2,
            ITEM_MARGIN_TOP + option.decorationSize.height() + ITEM_PADDING
        );
        fontBoundaries.translate(-fontBoundaries.topLeft());
        fontBoundaries.translate(textPos);
        fontBoundaries.translate(option.rect.topLeft());
        painter->setPen(foreColor);
        painter->drawText(fontBoundaries, Qt::AlignCenter, text);
    }
}
开发者ID:deiv,项目名称:plasmate-pkg,代码行数:61,代码来源:sidebardelegate.cpp


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