本文整理汇总了C++中QListView::style方法的典型用法代码示例。如果您正苦于以下问题:C++ QListView::style方法的具体用法?C++ QListView::style怎么用?C++ QListView::style使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListView
的用法示例。
在下文中一共展示了QListView::style方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintCell
void ConfigurationItem::paintCell(QPainter *p, const QColorGroup &cg, int column,
int width, int align)
{
if ( (column == 0) || (column == 1) || (column == 2) )
{
if ( !p )
return;
QListView *lv = listView();
if ( !lv )
return;
const BackgroundMode bgmode = lv->viewport()->backgroundMode();
const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( bgmode );
p->fillRect(0, 0, width, height(), cg.brush(crole));
QFontMetrics fm(lv->fontMetrics());
int boxsize = lv->style().pixelMetric(QStyle::PM_CheckListButtonSize, lv);
int marg = lv->itemMargin();
int styleflags = QStyle::Style_Default;
if (((column == 0) && m_contents) || ((column == 1) && m_index) || ((column == 2) && m_fullTextSearch))
styleflags |= QStyle::Style_On;
else
styleflags |= QStyle::Style_Off;
if ((column == 0) || ((column == 1) && m_indexPossible) || ((column == 2) && m_fullTextSearchPossible))
styleflags |= QStyle::Style_Enabled;
int x = 0;
int y = 0;
x += 3;
if (align & AlignVCenter)
y = ((height() - boxsize) / 2) + marg;
else
y = (fm.height() + 2 + marg - boxsize) / 2;
QStyleOption opt(this);
lv->style().drawPrimitive(QStyle::PE_CheckListIndicator, p,
QRect(x, y, boxsize, fm.height() + 2 + marg), cg, styleflags, opt);
return;
}
QListViewItem::paintCell(p, cg, column, width, align);
}
示例2: paintCell
void ChannelListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align )
{
QPixmap back( width, height() );
QPainter paint( &back );
//KListViewItem::paintCell( &paint, cg, column, width, align );
// PASTED FROM KLISTVIEWITEM:
// set the alternate cell background colour if necessary
QColorGroup _cg = cg;
if (isAlternate())
if (listView()->viewport()->backgroundMode()==Qt::FixedColor)
_cg.setColor(QColorGroup::Background, static_cast< KListView* >(listView())->alternateBackground());
else
_cg.setColor(QColorGroup::Base, static_cast< KListView* >(listView())->alternateBackground());
// PASTED FROM QLISTVIEWITEM
{
QPainter *p = &paint;
QListView *lv = listView();
if ( !lv )
return;
QFontMetrics fm( p->fontMetrics() );
// any text we render is done by the Components, not by this class, so make sure we've nothing to write
QString t;
// removed text truncating code from Qt - we do that differently, further on
int marg = lv->itemMargin();
int r = marg;
// const QPixmap * icon = pixmap( column );
const BackgroundMode bgmode = lv->viewport()->backgroundMode();
const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( bgmode );
if ( _cg.brush( crole ) != lv->colorGroup().brush( crole ) )
p->fillRect( 0, 0, width, height(), _cg.brush( crole ) );
else
{
// all copied from QListView::paintEmptyArea
//lv->paintEmptyArea( p, QRect( 0, 0, width, height() ) );
QStyleOption opt( lv->sortColumn(), 0 ); // ### hack; in 3.1, add a property in QListView and QHeader
QStyle::SFlags how = QStyle::Style_Default;
if ( lv->isEnabled() )
how |= QStyle::Style_Enabled;
lv->style().drawComplexControl( QStyle::CC_ListView,
p, lv, QRect( 0, 0, width, height() ), lv->colorGroup(),
how, QStyle::SC_ListView, QStyle::SC_None,
opt );
}
if ( isSelected() &&
(column == 0 || lv->allColumnsShowFocus()) ) {
p->fillRect( r - marg, 0, width - r + marg, height(),
_cg.brush( QColorGroup::Highlight ) );
// removed text pen setting code from Qt
}
// removed icon drawing code from Qt
// draw the tree gubbins
if ( multiLinesEnabled() && column == 0 && isOpen() && childCount() ) {
int textheight = fm.size( align, t ).height() + 2 * lv->itemMargin();
textheight = QMAX( textheight, QApplication::globalStrut().height() );
if ( textheight % 2 > 0 )
textheight++;
if ( textheight < height() ) {
int w = lv->treeStepSize() / 2;
lv->style().drawComplexControl( QStyle::CC_ListView, p, lv,
QRect( 0, textheight, w + 1, height() - textheight + 1 ), _cg,
lv->isEnabled() ? QStyle::Style_Enabled : QStyle::Style_Default,
QStyle::SC_ListViewExpand,
(uint)QStyle::SC_All, QStyleOption( this ) );
}
}
}
// END OF PASTE
//do you see a better way to tell the TextComponent we are selected ? - Olivier 2004-09-02
if ( isSelected() )
_cg.setColor(QColorGroup::Text , _cg.highlightedText() );
QSimpleRichText myrichtext( text(column), paint.font() );
myrichtext.draw( &paint, 0, 0, paint.window(), _cg );
paint.end();
p->drawPixmap( 0, 0, back );
}