add qpainterpath into a QProgressBar
-
I have a CustomWidget plugin. This widget is a QFrame with the below implementation hierarchy. My Widget is working well, but I am struggling with adding a qpainter diamond shape into the qProgressBar widget. If I change my parent to spValDiamond ( new QPainter( this ) ) my diamond appears fine in my outer frame. But when set it parent to the pvValBar spValDiamond ( new QPainter( pvValBar ) ) i seem to completely loose my diamond. I have attempted making the progressbar transparent with no success.
I am creating my image with QpainterPath and then attempting to insert that image into my QProgressBar. Once their, it will move with the spValLine.Controller::Controller( QWidget *parent ) : QFrame( parent ) , ctrlIdLabel( new QLabel ) , ctrlOnButton( new QPushButton ) , idOnOffHLayout( new QHBoxLayout ) , pvFillFrame( new QFrame ) , pvValBar( new QProgressBar ) , spValLine ( new QLineEdit( pvValBar ) ) , spValDiamond ( new QPainter( pvValBar ) ) , pvValEdit ( new QLineEdit( pvValBar ) ) , spValEdit ( new QLineEdit ) , pvSpVLayout( new QVBoxLayout ) , ssrValBar( new QProgressBar ) , pvSpSsrHLayout( new QHBoxLayout ) , ctrlVLayout( new QVBoxLayout ) { path = new QPainterPath(); QRectF rect(5, 10, 6, 8 ); path->moveTo(rect.center().x(), rect.top()); path->lineTo(rect.right(), rect.center().y()); path->lineTo(rect.center().x(), rect.bottom()); path->lineTo(rect.left(), rect.center().y()); path->lineTo(rect.center().x(), rect.top()); } void Controller::paintEvent( QPaintEvent* ) { ctrlOnOffButton(); pvProgressBarStyleSheet(); drawSpLine(); pvLineEditStyleSheet(); spLineEditStyleSheet(); ssrProgressBarStyleSheet(); } void Controller::drawSpLine() { int heightValue = (int)qRound( (float)m_spVal / m_spValMax * pvValBar->height() ); spValLine->move( 0, pvValBar->height() - heightValue ); spValDiamond->setBrush(QBrush(Qt::red)); spValDiamond->fillPath(*path, QBrush(Qt::red)); }
I assume I am just missing something simple. but any direction would be very helpful. Thank you.
-
Hi,
You can't paint on a different widget.
If you want to customize the QProgressBar, then you have to subclass it and do the painting in its own paintEvent.