Irregular progress chart
-
Hello,
Im currently trying to find best way to draw a chart, which shows progress of subpieces of an item. Im migrating from old Forms application where looked like this:
(grey meant not done, orange working, blue done)
In Forms it was achieved using bar chart with zero padding between hundreds/thousands of bars (of orange/blue series which were without offset)
It doesnt look like such styling is easily possible with QChart QBarSet, or is there some chart type ideal for this?
Alternative could also be to draw manually vertical lines to QImage and then draw it in paintEvent to fill some QWidget. Considering such information is additive (only draw more lines on top of existing chart/image during update) could this be better option? Is it even possible to draw more to shown image or whole image needs to be repainted?
Thank you for suggestions
-
I would simply draw the lines on a QImage when an update is coming in and then draw this image in the paintEvent() of a custom QWidget or QLabel.
-
I would simply draw the lines on a QImage when an update is coming in and then draw this image in the paintEvent() of a custom QWidget or QLabel.
@Christian-Ehrlicher
If I understand right, this would mean one QPainter in update function for drawing new lines on image (QPainter ::drawLine) + call repaint() or update(), and second inside paintEvent forQPainter painter(this); painter.drawImage(rect(), dataImage); painter.end();
It looks a bit wasteful to redraw it whole when only small parts change at a time, but is there a way to edit existing painted image? And I presume this would work for arbitrary image size (if I set image width to chart varying subparts count), and stretch accordingly?
-
@Christian-Ehrlicher
If I understand right, this would mean one QPainter in update function for drawing new lines on image (QPainter ::drawLine) + call repaint() or update(), and second inside paintEvent forQPainter painter(this); painter.drawImage(rect(), dataImage); painter.end();
It looks a bit wasteful to redraw it whole when only small parts change at a time, but is there a way to edit existing painted image? And I presume this would work for arbitrary image size (if I set image width to chart varying subparts count), and stretch accordingly?
@raziel said in Irregular progress chart:
but is there a way to edit existing painted image?
No it isn't.
You can call update() (repaint is a forced draw which is not really needed in 99,9% of all cases) with a dirty rect and then set the clip rect so QPainter draws only in the clip rect if you've performance problems.
-
@raziel said in Irregular progress chart:
but is there a way to edit existing painted image?
No it isn't.
You can call update() (repaint is a forced draw which is not really needed in 99,9% of all cases) with a dirty rect and then set the clip rect so QPainter draws only in the clip rect if you've performance problems.
Thank you, it works fairly well
although there is a bit of unwanted blurring (bilinear filtering?) despite usingpixmap.scaled(widgetWidth, 1, Qt::IgnoreAspectRatio, Qt::FastTransformation)
which does help, but not completely.
Do you know if there is possibility to turn off filtering completely for sharp pixelated image?
-
Thank you, it works fairly well
although there is a bit of unwanted blurring (bilinear filtering?) despite usingpixmap.scaled(widgetWidth, 1, Qt::IgnoreAspectRatio, Qt::FastTransformation)
which does help, but not completely.
Do you know if there is possibility to turn off filtering completely for sharp pixelated image?
@raziel said in Irregular progress chart:
Do you know if there is possibility to turn off filtering completely for sharp pixelated image?
I would resize the QImage to the current width of the widget and do the painting in there, maybe with a QTransform on the painter to avoid the needed calculations by yourself.
-
@raziel said in Irregular progress chart:
Do you know if there is possibility to turn off filtering completely for sharp pixelated image?
I would resize the QImage to the current width of the widget and do the painting in there, maybe with a QTransform on the painter to avoid the needed calculations by yourself.
@Christian-Ehrlicher
Ah I found the culprit. Target label widget reports smaller width during initialization (after setupUi), where I created QImage for testing. Later (eg. in timer) it reports correct bigger width. Which is strange, designer shows in properties proper bigger width, are these designed properties not yet fully set after setupUi? -
@Christian-Ehrlicher
Ah I found the culprit. Target label widget reports smaller width during initialization (after setupUi), where I created QImage for testing. Later (eg. in timer) it reports correct bigger width. Which is strange, designer shows in properties proper bigger width, are these designed properties not yet fully set after setupUi?@raziel said in Irregular progress chart:
are these designed properties not yet fully set after setupUi?
The layout manager adjusts the widgets during the showEvent() to make sure everything fits.