Exemple #1
0
void HGauge::draw(QPainter* painter)
{
	painter->fillRect(rect_, QBrush(baseColor_) );

	if( currentValue_ < minValue_ )
		currentValue_ = minValue_;
	else if( currentValue_ > maxValue_ )
		currentValue_ = maxValue_;

	QRect percentRect(rect_.x(), rect_.y(),
			(int)( ((double)((double)currentValue_ / (double)maxValue_)) * (double)rect_.width() ),
			rect_.height() );
	painter->fillRect(percentRect, QBrush(gaugeColor_) );
}
Exemple #2
0
    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    {
        QStyleOptionViewItem newOption;
        newOption = option;
        newOption.state &= ~QStyle::State_HasFocus;
        newOption.palette.setColor( QPalette::Disabled, QPalette::Text, Qt::black );

        QTableWidget* pWidget = static_cast<QTableWidget*>( parent() );
        RecentTableWidgetItem* pItem = static_cast<RecentTableWidgetItem*>(pWidget->item(index.row(), index.column()));

        painter->setFont(fontTitle);
        QFontMetrics tfm(fontTitle);
        int fontTitleSize = tfm.height();
        QRect titleRect( newOption.rect.x(), newOption.rect.y(), newOption.rect.width(), fontTitleSize );
        painter->drawText( titleRect, Qt::TextSingleLine, tfm.elidedText(pItem->title, Qt::ElideRight, newOption.rect.width() ));

        painter->setFont(fontInfo);
        QFontMetrics ifm(fontInfo);
        int fontAuthorSize = ifm.height();
        QRect infoRect( newOption.rect.x(), newOption.rect.y() + fontTitleSize, newOption.rect.width(), fontAuthorSize );

        int percentWidth = ifm.boundingRect(pItem->percent).width();
        infoRect.adjust(0,0,-percentWidth,0);

        painter->drawText( infoRect, Qt::TextSingleLine, ifm.elidedText(pItem->info, Qt::ElideRight, infoRect.width() ) );

        QRect percentRect( infoRect.right(), infoRect.top(), percentWidth, infoRect.height() );
        painter->drawText( percentRect, Qt::TextSingleLine, pItem->percent );

        if (index.flags() & Qt::ItemIsSelectable)
        {
            Qt::GlobalColor lineColor = Qt::black;
            int lineWidth = newOption.state & QStyle::State_Selected ? 5:0;
            QPen pen(lineColor, lineWidth, Qt::SolidLine);
            painter->setPen(pen);
            painter->drawLine(newOption.rect.left(), newOption.rect.bottom()-lineWidth/2, newOption.rect.right(), newOption.rect.bottom()-lineWidth/2);
        }
    }