PDA

View Full Version : Height by value on a Custom Progress Bar ?



MathFurious
7th February 2018, 13:07
Hi,

I want to create a flat progress bar with QPainter, I paint graphics with the fallowing code:



QPainter painter(this);

// Bar Background
painter.setBrush(QBrush(Qt::white));
painter.setPen(Qt::NoPen);
painter.drawRect(0, 0, m_width, this->height());

// Bar Value
painter.setBrush(QBrush(m_fillColor));

if (m_value == 0)
{
return;
}

qDebug() << "Value: " << m_value;
qDebug() << "Height: " << this->height();

int heightValue = (this->height() / m_value);

qDebug() << "HValue: " << heightValue;

painter.drawRect(0, 0, m_width, heightValue);


But I tried some calculation for set the height of the progress bar with the progress bar value but nothing works...

Lesiok
7th February 2018, 13:47
What it is "nothing works" ?

MathFurious
7th February 2018, 19:15
Sorry, I found how to do what I want, thank anyway for reply.

Ginsengelf
8th February 2018, 07:01
... and if you would post your solution others would probably be happy as well.

Ginsengelf

MathFurious
8th February 2018, 14:30
int heightValue = (int)qRound(((float)currentValue / maxProgressBarValue) * heightOfTheProgressBar);


And I draw with QPainter a rectangle like that:


painter.drawRect(0, 0, 100, heightValue);