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


C++ QStyle类代码示例

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


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

示例1: paint

void NoteItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    QStyle* style = KApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);

    QRect rect = option.rect;
    rect.adjust( m_margin, m_margin, -m_margin, -m_margin );

    Nepomuk2::Resource res = index.data( Nepomuk2::Utils::SimpleResourceModel::ResourceRole ).value<Nepomuk2::Resource>();

    QString plainTextContent = res.property( NIE::plainTextContent() ).toString();
    QDateTime creationDate = res.property( NAO::created() ).toDateTime();

    //TODO: Find a way to convert this date into "4 hours ago" format
    QString dateString = creationDate.toLocalTime().toString();

    painter->save();
    QFont f = painter->font();
    f.setBold( true );
    painter->setFont( f );
    style->drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignTop, option.palette, true, dateString );
    painter->restore();

    rect.setY( rect.y() + QFontMetrics(f).height()/* + m_margin */);

    //
    // Draw the excerpt
    //
    QTextDocument textDocument;
    textDocument.setTextWidth( rect.width() );

    QFont font = textDocument.defaultFont();
    font.setItalic( true );
    textDocument.setDefaultFont( font );

    QFontMetrics fm( font );
    int numLines = rect.height() / fm.height();
    int charPerLine = rect.width() / fm.averageCharWidth();

    int l = (numLines-2) * charPerLine; // one line less for ending, and one line for padding
    QString text;
    // FIXME: There may be a case where some part of the text gets repeated before and after the ...
    if( l < plainTextContent.length() ) {
        text = plainTextContent.left( l );
        text += QLatin1String(" .... ");
        text += plainTextContent.right( charPerLine-10 );
    }
    else {
        text = plainTextContent;
    }

    textDocument.setPlainText( text.simplified() );

    painter->save();
    painter->translate( rect.topLeft() );
    textDocument.drawContents( painter );
    painter->restore();
}
开发者ID:KDE,项目名称:notably,代码行数:58,代码来源:noteitemdelegate.cpp

示例2: if

void RepoItemDelegate::paintRepoCategoryItem(QPainter *painter,
                                             const QStyleOptionViewItem& option,
                                             const RepoCategoryItem *item) const
{
    QBrush backBrush;
    QColor foreColor;
    bool hover = false;
    bool selected = false;

    if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) {
        backBrush = option.palette.brush(QPalette::Highlight);
        foreColor = option.palette.color(QPalette::HighlightedText);
        selected = true;

    } else if (option.state & QStyle::State_MouseOver) {
        backBrush = option.palette.color(QPalette::Highlight).lighter(115);
        foreColor = option.palette.color(QPalette::HighlightedText);
        hover = true;

    } else {
        backBrush = option.palette.brush(QPalette::Base);
        foreColor = option.palette.color(QPalette::Text);
    }

    QStyle *style = QApplication::style();
    QStyleOptionViewItemV4 opt(option);
    opt.backgroundBrush = backBrush;
    painter->save();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, 0);
    painter->restore();

    // Paint the expand/collapse indicator
    RepoTreeModel *model = (RepoTreeModel *)item->model();
    RepoTreeView *view = model->treeView();
    bool expanded = view->isExpanded(model->indexFromItem(item));

    QRect indicator_rect(option.rect.topLeft(),
                         option.rect.bottomLeft() + QPoint(option.rect.height(), 0));
    painter->save();
    painter->setPen(foreColor);
    painter->setFont(awesome->font(16));
    painter->drawText(indicator_rect,
                      Qt::AlignCenter,
                      QChar(expanded ? icon_caret_down : icon_caret_right),
                      &indicator_rect);
    painter->restore();

    // Paint category name
    painter->save();
    QPoint category_name_pos = indicator_rect.topRight() + QPoint(kMarginBetweenIndicatorAndName, 0);
    QRect category_name_rect(category_name_pos,
                             option.rect.bottomRight() - QPoint(kPadding, 0));
    painter->setPen(foreColor);
    painter->drawText(category_name_rect,
                      Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap,
                      fitTextToWidth(item->name(), option.font, category_name_rect.width()));
    painter->restore();
}
开发者ID:Greyhatno,项目名称:seafile-client,代码行数:58,代码来源:repo-item-delegate.cpp

示例3: QColor

void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index ) const
{
    painter->save();

    QTextDocument doc;
    QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );

    QAbstractTextDocumentLayout::PaintContext ctx;
    QStyleOptionViewItemV4 optionV4 = option;

    QColor color;
    if ( option.state & QStyle::State_Selected && option.state & QStyle::State_HasFocus )
    {
        color = QColor( 255, 255, 255, 60 );
        ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Active, QPalette::HighlightedText ) );

        QStyle *style = QApplication::style();
        style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL );
    }
    else if ( option.state & QStyle::State_Enabled )
    {
        color = QColor( 100, 100, 100, 30 );
        ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Active, QPalette::Text ) );

        QStyle *style = QApplication::style();
        style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL );
    }
    else
    {
        color = QColor( 100, 100, 100, 30 );
        ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Disabled, QPalette::Text ) );
    }

    painter->setRenderHint( QPainter::Antialiasing );
    painter->setPen( QColor( 0, 0, 0, 0 ) );
    painter->setBrush( QBrush( color ) );
    painter->drawRoundedRect( option.rect.left() + 5, option.rect.top() + 5, option.rect.width() - 10, option.rect.height() - 10, 8, 8 );

    int titleSize = QApplication::fontMetrics().height() * 1.1;
    int textSize = titleSize * 0.85;

    doc.setHtml( QString( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize )
                 .arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString(),
                       index.data( QgsWelcomePageItemsModel::PathRole ).toString(),
                       index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
    doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );

    if ( !icon.isNull() )
    {
        painter->drawPixmap( option.rect.left() + 10, option.rect.top()  + 10, icon );
    }

    painter->translate( option.rect.left() + ( !icon.isNull() ? icon.width() + 25 : 15 ), option.rect.top() + 15 );
    ctx.clip = QRect( 0, 0, option.rect.width() - ( !icon.isNull() ? icon.width() - 35 : 25 ), option.rect.height() - 25 );
    doc.documentLayout()->draw( painter, ctx );

    painter->restore();
}
开发者ID:rhurlin,项目名称:QGIS,代码行数:58,代码来源:qgswelcomepageitemsmodel.cpp

示例4: QTreeWidget

//=========================================================================
hTreeBrowser::hTreeBrowser(QWidget *parent, MainWindow * mainWindow)
    : QTreeWidget   (parent)
    , parent_       (parent->parentWidget())
    , theMainWindow_(mainWindow)
    , currentCanvas_(0)
    , canvasPosX_   (5)
    , canvasPosY_   (5)
    , canvasWitdh_  (800)
    , canvasHeight_ (600)
    , currentObject_(0)
{
    //    theHManager_   = theMainWindow_->getHManager()   ;
    serviceCanvas_.clear();
    cSw_.clear() ;

    QStringList labels;
    labels << tr("Folder Name") << tr("Object Type") << tr("Entries");
    this->setHeaderLabels(labels);
    this->header()->setResizeMode(0, QHeaderView::Interactive);
    this->header()->setResizeMode(1, QHeaderView::Interactive);
    this->header()->setResizeMode(2, QHeaderView::Interactive);

    this->header()->setDefaultSectionSize(200);

    this->setContextMenuPolicy(Qt::CustomContextMenu);

    QStyle *style = parent_->style();

    QString imagesDir = QString(getenv("CHEWIEDIR")) + "/images/";
    QPixmap closedFolderPM(imagesDir+"ClosedFolder.png");
    QPixmap openFolderPM  (imagesDir+"OpenFolder.png"  );
    QPixmap TH1IconPM     (imagesDir+"TH1Icon.png"     );
    QPixmap TH2IconPM     (imagesDir+"TH2Icon.png"     );
    QPixmap TTreePM       (imagesDir+"TreeIcon.png"    );
    QPixmap TGraphPM      (imagesDir+"TGraphIcon.png"  );
    QPixmap TProfilePM    (imagesDir+"TProfileIcon.png");

    folderIcon_  .addPixmap(closedFolderPM, QIcon::Normal, QIcon::Off      );
    folderIcon_  .addPixmap(openFolderPM,   QIcon::Normal, QIcon::On       );
    canvasIcon_  .addPixmap(style->standardPixmap(QStyle::SP_FileIcon     ));
    TH1Icon_     .addPixmap(TH1IconPM                                      );
    TH2Icon_     .addPixmap(TH2IconPM                                      );
    tTreeIcon_   .addPixmap(TTreePM                                        );
    tGraphIcon_  .addPixmap(TGraphPM                                       );
    tProfileIcon_.addPixmap(TProfilePM                                     );
    mainIcon_    .addPixmap(style->standardPixmap(QStyle::SP_DriveHDIcon  ));

    this->setAnimated(true);

    this->setSelectionMode(QAbstractItemView::ExtendedSelection);

    QObject::connect(this, SIGNAL(customContextMenuRequested( const QPoint         &     )),
                     this, SLOT(  showContextMenu           ( const QPoint         &     ))) ;
    QObject::connect(this, SIGNAL(itemClicked               (       QTreeWidgetItem*, int)),
                     this, SLOT(  manipulateFolder          (       QTreeWidgetItem*, int))) ;
    //QObject::connect(this, SIGNAL(itemEntered               (       QTreeWidgetItem*, int)),
    //                 this, SLOT(  showHint                  (       QTreeWidgetItem*, int))) ;
}
开发者ID:sakamoto-poteko,项目名称:Chewie,代码行数:59,代码来源:hTreeBrowser.cpp

示例5: Q_UNUSED

void ExpandingDelegate::drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    Q_UNUSED(index)
    QStyleOptionViewItemV4 opt = option;
    //initStyleOption(&opt, index);
    //Problem: This isn't called at all, because drawBrackground is not virtual :-/
    QStyle *style = model()->treeView()->style() ? model()->treeView()->style() : QApplication::style();
    style->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
}
开发者ID:benpope82,项目名称:ktexteditor,代码行数:9,代码来源:expandingdelegate.cpp

示例6: keys

/*!
    Creates and returns a QStyle object that matches the given \a key, or
    returns 0 if no matching style is found.

    Both built-in styles and styles from style plugins are queried for a
    matching style.

    \note The keys used are case insensitive.

    \sa keys()
*/
QStyle *QStyleFactory::create(const QString& key)
{
    QStyle *ret = 0;
    QString style = key.toLower();
#ifndef QT_NO_STYLE_WINDOWS
    if (style == QLatin1String("windows"))
        ret = new QWindowsStyle;
    else
#endif
#ifndef QT_NO_STYLE_WINDOWSCE
    if (style == QLatin1String("windowsce"))
        ret = new QWindowsCEStyle;
    else
#endif
#ifndef QT_NO_STYLE_WINDOWSMOBILE
    if (style == QLatin1String("windowsmobile"))
        ret = new QWindowsMobileStyle;
    else
#endif
#ifndef QT_NO_STYLE_WINDOWSXP
    if (style == QLatin1String("windowsxp"))
        ret = new QWindowsXPStyle;
    else
#endif
#ifndef QT_NO_STYLE_WINDOWSVISTA
    if (style == QLatin1String("windowsvista"))
        ret = new QWindowsVistaStyle;
    else
#endif
#ifndef QT_NO_STYLE_FUSION
    if (style == QLatin1String("fusion"))
        ret = new QFusionStyle;
    else
#endif
#ifndef QT_NO_STYLE_GTK
    if (style == QLatin1String("gtk") || style == QLatin1String("gtk+"))
        ret = new QGtkStyle;
    else
#endif
#ifndef QT_NO_STYLE_MAC
    if (style.startsWith(QLatin1String("macintosh"))) {
        ret = new QMacStyle;
#  ifdef Q_WS_MAC
        if (style == QLatin1String("macintosh"))
            style += QLatin1String(" (aqua)");
#  endif
    } else
#endif
    { } // Keep these here - they make the #ifdefery above work
#ifndef QT_NO_LIBRARY
    if (!ret)
        ret = qLoadPlugin<QStyle, QStylePlugin>(loader(), style);
#endif
    if(ret)
        ret->setObjectName(style);
    return ret;
}
开发者ID:ghjinlei,项目名称:qt5,代码行数:68,代码来源:qstylefactory.cpp

示例7: QSize

/*!
  \brief Gets the suitable size of project window.
  This size is just suitable for the whole project area with 1px border and
  the scroll bar.
  \return suitable size of this project window
 */
QSize Ui::ProjectWindow::sizeHint() const
{
    QStyle *style = qApp->style();
    int frameBorderWidth = style->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth);
    int frameTitleHeight = style->pixelMetric(QStyle::PM_TitleBarHeight);
    int scrollBarWidth = style->pixelMetric(QStyle::PM_ScrollBarExtent);
    return QSize(view->width() + (frameBorderWidth << 1) + scrollBarWidth + 2,
                 view->height() + frameTitleHeight + frameBorderWidth + statusBar->height() - 10);
}
开发者ID:jaisurya,项目名称:picworks,代码行数:15,代码来源:projectwindow.cpp

示例8: getStyle

int ViewHelpMenu::getStyle() const {
    QStyle * style = QApplication::style();
    const QMetaObject * mo = style->metaObject();
	for(uint i = 0 ; i < __ids.size() ; i++){
		if((QStyleFactory::create(__ids[i]->text()))->metaObject() == mo)
			return i;
	}
	return -1;
}
开发者ID:kkremitzki,项目名称:plantgl,代码行数:9,代码来源:helpmenu.cpp

示例9: chooseStyle

void DStyleComboBox::chooseStyle(const QString &style)
{
	QStyle *st = QStyleFactory::create( style );
	if(st)
	{
		qApp->setStyle( st );
		qApp->setPalette(st->standardPalette());
	}
}
开发者ID:BackupTheBerlios,项目名称:khess-svn,代码行数:9,代码来源:dstylecombobox.cpp

示例10: initStyleOption

void UserDelegate::paint(QPainter * painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
	const QAbstractItemModel *m = index.model();
	const QModelIndex idxc1 = index.sibling(index.row(), 1);
	QVariant data = m->data(idxc1);
	QList<QVariant> ql = data.toList();

	painter->save();

	QStyleOptionViewItemV4 o = option;
	initStyleOption(&o, index);

	QStyle *style = o.widget->style();
	QIcon::Mode iconMode = QIcon::Normal;

	QPalette::ColorRole colorRole = ((o.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text);
#if defined(Q_OS_WIN)
	// Qt's Vista Style has the wrong highlight color for treeview items
	// We can't check for QStyleSheetStyle so we have to search the children list search for a QWindowsVistaStyle
	QList<QObject *> hierarchy = style->findChildren<QObject *>();
	hierarchy.insert(0, style);
	foreach (QObject *obj, hierarchy) {
		if (QString::fromUtf8(obj->metaObject()->className()) == QString::fromUtf8("QWindowsVistaStyle")) {
			colorRole = QPalette::Text;
			break;
		}
	}
#endif

	// draw background
	style->drawPrimitive(QStyle::PE_PanelItemViewItem, &o, painter, o.widget);

	// resize rect to exclude the flag icons
	o.rect = option.rect.adjusted(0, 0, -18 * ql.count(), 0);

	// draw icon
	QRect decorationRect = style->subElementRect(QStyle::SE_ItemViewItemDecoration, &o, o.widget);
	o.icon.paint(painter, decorationRect, o.decorationAlignment, iconMode, QIcon::On);

	// draw text
	QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &o, o.widget);
	QString itemText = o.fontMetrics.elidedText(o.text, o.textElideMode, textRect.width());
	painter->setFont(o.font);
	style->drawItemText(painter, textRect, o.displayAlignment, o.palette, true, itemText, colorRole);

	// draw flag icons to original rect
	QRect ps = QRect(option.rect.right() - (ql.size() * 18), option.rect.y(), ql.size() * 18, option.rect.height());
	for (int i = 0; i < ql.size(); ++i) {
		QRect r = ps;
		r.setSize(QSize(16, 16));
		r.translate(i * 18 + 1, 1);
		QRect p = QStyle::alignedRect(option.direction, option.decorationAlignment, r.size(), r);
		qvariant_cast<QIcon>(ql[i]).paint(painter, p, option.decorationAlignment, iconMode, QIcon::On);
	}

	painter->restore();
}
开发者ID:Durlockozk,项目名称:mumble,代码行数:56,代码来源:UserView.cpp

示例11: initStyleOption

void KOTodoRichTextDelegate::paint( QPainter *painter,
                                    const QStyleOptionViewItem &option,
                                    const QModelIndex &index ) const
{
  if ( index.data( KOTodoModel::IsRichTextRole ).toBool() ) {
    QStyleOptionViewItemV4 opt = option;
    initStyleOption( &opt, index );

    const QWidget *widget = opt.widget;
    QStyle *style = widget ? widget->style() : QApplication::style();

    QRect textRect = style->subElementRect( QStyle::SE_ItemViewItemText,
                                            &opt, widget );

    // draw the item without text
    opt.text.clear();
    style->drawControl( QStyle::CE_ItemViewItem, &opt, painter, widget );

    // draw the text (rich text)
    QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ?
                                QPalette::Normal : QPalette::Disabled;
    if ( cg == QPalette::Normal && !( opt.state & QStyle::State_Active ) ) {
      cg = QPalette::Inactive;
    }

    if ( opt.state & QStyle::State_Selected ) {
      painter->setPen(
        QPen( opt.palette.brush( cg, QPalette::HighlightedText ), 0 ) );
    } else {
      painter->setPen(
        QPen( opt.palette.brush( cg, QPalette::Text ), 0 ) );
    }
    if ( opt.state & QStyle::State_Editing ) {
      painter->setPen( QPen( opt.palette.brush( cg, QPalette::Text ), 0 ) );
      painter->drawRect( textRect.adjusted( 0, 0, -1, -1 ) );
    }

    m_textDoc->setHtml( index.data().toString() );

    painter->save();
    painter->translate( textRect.topLeft() );

    QRect tmpRect = textRect;
    tmpRect.moveTo( 0, 0 );
    m_textDoc->setTextWidth( tmpRect.width() );
    m_textDoc->drawContents( painter, tmpRect );

    painter->restore();
  } else {
    // align the text at top so that when it has more than two lines
    // it will just cut the extra lines out instead of aligning centered vertically
    QStyleOptionViewItem copy = option;
    copy.displayAlignment = Qt::AlignLeft | Qt::AlignTop;
    QStyledItemDelegate::paint( painter, copy, index );
  }
}
开发者ID:jaydp17,项目名称:todoview-files,代码行数:56,代码来源:kotododelegates.cpp

示例12: horizontalScrollbarHeight

int PlatformScrollbar::horizontalScrollbarHeight(ScrollbarControlSize controlSize)
{
    QStyle *s = QApplication::style();
    QStyleOptionSlider o;
    o.orientation = Qt::Horizontal;
    o.state |= QStyle::State_Horizontal;
    if (controlSize != RegularScrollbar)
        o.state |= QStyle::State_Mini;
    return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0);
}
开发者ID:FilipBE,项目名称:qtextended,代码行数:10,代码来源:PlatformScrollBarQt.cpp

示例13: scrollbarThickness

int ScrollbarThemeQt::scrollbarThickness(ScrollbarControlSize controlSize)
{
    QStyle* s = QApplication::style();
    QStyleOptionSlider o;
    o.orientation = Qt::Vertical;
    o.state &= ~QStyle::State_Horizontal;
    if (controlSize != RegularScrollbar)
        o.state |= QStyle::State_Mini;
    return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0);
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例14: tree_widget

    XMLParameterReader::XMLParameterReader(QTreeWidget *tree_widget)
                      : tree_widget(tree_widget)
    {
      QStyle * style = tree_widget->style();

      subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off);
      subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On);

      parameter_icon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon));
    }
开发者ID:ClairePoliMi,项目名称:dealii,代码行数:10,代码来源:xml_parameter_reader.cpp

示例15: defaultDisplayText

void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                         const QModelIndex &index) const
{
    QStyleOptionViewItem opt = option;
    opt.text = defaultDisplayText(index);
    initStyleOption(&opt, index);

    const QWidget *widget = this->widget(option);
    QStyle *style = this->style(option);
    style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
}
开发者ID:KDAB,项目名称:GammaRay,代码行数:11,代码来源:itemdelegate.cpp


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