I have a diary program in which user can create tasks and then add breaks to them. Each Task
object has a QTime start_time
, QTime end_time
and vector
of Break
s. Each Break
has a QTime start_time
and QTime end_time
members, just like a Task
. I want to visualize the progress on a current task by using custom QProgressBar
to show the "timeline". It should be a green line separated by red chunks that represent breaks and a triangle above it to indicate current progress. Here's my top quality drawing:
Requirements: The triangle should smoothly move towards the end every minute or so and not hop. It also has to change its color depending if it on a red chunk or green. The line has to be resizable, but that shouldn't affect task
s or break
s time variables. User can't add multiple breaks with consequent time.
Now my question is, is this even possible? If yes, then how?
I tried to make a task without breaks to draw just a green line and a triangle without red chunks, but I immediately faced a problem with resizing. If line width increases then the triangle's "step" by minute should increase too. I tried to implement that, but didn't find much success.
Here's the code:
//class CustomProgressBar: public QProgressBar
void CustomProgressBar::paintEvent(QPaintEvent* event)
{
setMaximum(this->width());
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
QPoint start_point;
start_point.setX(0);
start_point.setY(13);
QPoint end_point;
end_point.setY(13);
end_point.setX(this->width()); //has to be resizable
//"TimeLine"
painter.setPen(QPen(Qt::green, 2, Qt::SolidLine, Qt::RoundCap));
painter.drawLine(start_point, end_point);
//Triangle
int progress = this->value();
QPoint triangle_start_point;
triangle_start_point.setX(this->value() + this->width() / 15 + 1);
triangle_start_point.setY(0);
QPoint triangle_bot_point;
triangle_bot_point.setX(this->value() + this->width() / 15 + 6);
triangle_bot_point.setY(10);
QPoint triangle_top_point;
triangle_top_point.setX(this->value() + this->width() / 15 + 11);
triangle_top_point.setY(0);
QPainterPath path;
path.moveTo(triangle_start_point);
path.lineTo(triangle_bot_point);
path.lineTo(triangle_top_point);
path.lineTo(triangle_start_point);
painter.setPen (Qt :: NoPen);
painter.fillPath(path, QBrush(QColor (Qt::green)));
}