void IconDelegate::_PaintBlue( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex & index ) const { QColor itemColor(Qt::blue);//Qt::GlobalColor QPen penLine; //setSybol rect QRect rectForSybol = _GetSybolRectForGray(option); penLine.setColor(itemColor); painter->setPen(penLine); painter->setBrush(itemColor);//设置画刷颜色 painter->drawEllipse(rectForSybol); }
void IconDelegate::_PaintRed( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex & index ) const { QColor itemColor(Qt::red);//Qt::GlobalColor QPen penLine; //setSybol rect QRect rectForSybol = _GetSybolRectForGreenRed(option); QPolygon sybolQPolygon = _GetSybolQPolygonForRed(rectForSybol); penLine.setColor(itemColor); painter->setPen(penLine); painter->setBrush(itemColor);//设置画刷颜色 painter->drawPolygon(sybolQPolygon); }
void GraphicsMovieItem::paintRect( QPainter* painter, const QStyleOptionGraphicsItem* option ) { QRectF drawRect; bool drawRound; // Disable the matrix transformations painter->setWorldMatrixEnabled( false ); painter->setRenderHint( QPainter::Antialiasing ); // Get the transformations required to map the text on the viewport QTransform viewPortTransform = Timeline::getInstance()->tracksView()->viewportTransform(); // Determine if a drawing optimization can be used if ( option->exposedRect.left() > AbstractGraphicsItem::RounderRectRadius && option->exposedRect.right() < boundingRect().right() - AbstractGraphicsItem::RounderRectRadius ) { // Optimized: paint only the exposed (horizontal) area drawRect = QRectF( option->exposedRect.left(), boundingRect().top(), option->exposedRect.right(), boundingRect().bottom() ); drawRound = false; } else { // Unoptimized: the item must be fully repaint drawRect = boundingRect(); drawRound = true; } // Do the transformation QRectF mapped = deviceTransform( viewPortTransform ).mapRect( drawRect ); QLinearGradient gradient( mapped.topLeft(), mapped.bottomLeft() ); gradient.setColorAt( 0, QColor::fromRgb( 78, 78, 78 ) ); gradient.setColorAt( 0.4, QColor::fromRgb( 72, 72, 72 ) ); gradient.setColorAt( 0.4, QColor::fromRgb( 50, 50, 50 ) ); gradient.setColorAt( 1, QColor::fromRgb( 45, 45, 45 ) ); painter->setPen( Qt::NoPen ); painter->setBrush( QBrush( gradient ) ); if ( drawRound ) painter->drawRoundedRect( mapped, AbstractGraphicsItem::RounderRectRadius, AbstractGraphicsItem::RounderRectRadius ); else painter->drawRect( mapped ); if ( itemColor().isValid() ) { QRectF mediaColorRect = mapped.adjusted( 3, 2, -3, -2 ); painter->setPen( QPen( itemColor(), 2 ) ); painter->drawLine( mediaColorRect.topLeft(), mediaColorRect.topRight() ); } if ( isSelected() ) { setZValue( zSelected() ); painter->setPen( Qt::yellow ); painter->setBrush( Qt::NoBrush ); mapped.adjust( 0, 0, 0, -1 ); if ( drawRound ) painter->drawRoundedRect( mapped, AbstractGraphicsItem::RounderRectRadius, AbstractGraphicsItem::RounderRectRadius); else painter->drawRect( mapped ); } else setZValue( zNotSelected() ); }