issue with QChartView (v.5.15.12)
-
Something wrong appears to happen when the class receives a resize event.
here is what my derived class logs with:
void BalanceChartView::resizeEvent(QResizeEvent *event) { QtCharts::QChartView::resizeEvent(event); qDebug() << "QChartView:" << size() << ", chart:" << chart()->rect() << "viewport:" << viewport()->size(); }
QChartView: QSize(671, 400) , chart: QRectF(0,0 671x400) viewport: QSize(638, 478)
no idea how the viewport ends up with those weird values but this is causing clipping when the chart is painted...
-
I have added
viewport()->resize(size());
to my QChartView derived class resizeEvent handler and this is fixing the problem...
I do not fully understand all the intricacies of the GraphicView but I would have expected that changing the Scene rect would also modify its viewport size as well. It appears that it is not the case...
I am stumbled by this realization but maybe it makes sense and there is some concept that escape my understanding...
-
@SGaist thx for the tips... I'll will look into how fitInView is implemented... maybe it is the right way to address the problem... maybe it is not...
the problem that I have with QChartView is not that it does not resize the chart and the containing scene... It does... it is that the viewport child widget is not resized...
I would expect this to happen automatically. I suspect that this is the expected behavior too by the QChartView author if not, he would not go through the trouble to resize the chart if the view is not expected to change from its initial size...
-
@lano1106
I started to have a go at looking at your question. But there is a distinct lack of a full example so I have no idea about your situation/what you are trying to do.What UI do you have? Where is the chart view? How/why does your chart view receive a resize event? From code, from the user resizing the containing widget?
FWIW I just created a
QWidget
and put aQChartView
on it. noviewport()->resize()
. When it shows initially I getQChartView: QSize(178, 78) , chart: QRectF(0,0 178x78) viewport: QSize(178, 78)
and if a drag-resize the widget I get
QChartView: QSize(296, 225) , chart: QRectF(0,0 296x225) viewport: QSize(296, 225)
So my viewport is always same as chart view/chart size.
I suggest you create and show a minimal example.
Btw
I do not fully understand all the intricacies of the GraphicView but I would have expected that changing the Scene rect would also modify its viewport size as well.
Changing
QGraphicsScene
size/rect does not modify eitherQGraphicsView
or its viewport, nor should it. Just in case you are doing so, callingQChart::resize()
does not affect eitherQChartView
or its viewport.