Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-81111

QChart not resizing when its QChartView is resized

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.14.0
    • Fix Version/s: None
    • Component/s: Charts
    • Labels:
      None
    • Environment:
      linux X11
    • Platform/s:
      Linux/X11

      Description

      I have first reported the issue on the forum:

      https://forum.qt.io/topic/110370/issue-with-qchart-layout-when-resizing-the-parent-qchartview-qt-5-14-0
      There is something wrong around the QChart layouts.

      Its containing QChartView receive a resize event but the chart stays in the old size. The only way to have it refreshed is when a QGraphicsItem (QGraphicsSimpleTextItem) that I added myself in the scene() along with the chart gets updated. This is not a viable solution because the chart stays in its old size for as long as the user doesn't interact with the chart.

      On my first attempt to fix that, I did try to override the QChartView::resizeEvent() method by doing this:
      {{void LinkedChartView::resizeEvent(QResizeEvent *event)
      {
      QChartView::resizeEvent(event);
      chart()->update();
      }}}
      to my great surprise calling update() on a QChart object does nothing. This is either very counter-intuitive or maybe it should do something and it doesn't for the same bug that make the chart not resize in the first place.

      Finally, the workaround that works is:
      {{void LinkedChartView::resizeEvent(QResizeEvent *event)
      {
      QChartView::resizeEvent(event);
      chart()>layout()>invalidate();
      chart()>layout()>activate();
      }}}
      Again, I suspect that if the code was working as designed my workaround wouldn't be neccessary....

       
      Here is some more context.

      I have 3 charts containing QLineSeries and some QScatterSeries, a QValueAxis vertically and a QDateTimeAxis horizontally.

      Those 3 charts view are placed into a QVBoxLayout.

      The chart view visibility is toggled on and off with the menu described in
      https://forum.qt.io/topic/110369/why-is-qt-makes-it-hard-to-activate-a-qaction-with-menu-from-qmenu

      The sure fire way to trigger the problem is hide and show the middle chart.

      The top most chart gets resized fine. I suspect it is because when the menu disappear that overlap a little bit the chart on its upper left corner, the chart is marked as dirty and needs to be repainted anyway.

      It is the chart at the bottom that needs my workaround to be resized properly.

       

      The Chart layout glitch may also explain the grid not resizing as seen at:

      https://forum.qt.io/topic/109997/i-had-an-incredible-hard-time-to-align-horizontally-3-charts-qt-5-13-2

       

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              e0348803 Miikka Heikkinen
              Reporter:
              lano1106 Olivier Langlois
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes