Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I had an incredible hard time to align horizontally 3 charts (Qt 5.13.2)

I had an incredible hard time to align horizontally 3 charts (Qt 5.13.2)

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 360 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lano1106
    wrote on last edited by lano1106
    #1

    The initial issue that I had was that 3 charts placed into a QVBoxLayout, having identical X axis were not aligned because the topmost chart Y axis labels were longer than the 2 other charts:
    aligned charts

    As you can see, I have finally succeeded but in the long and hard journey to find a working way, I think that I have stumbled into a serie of small QtCharts glitches. Therefore, I am documenting here what I have observed to help you guys improving the code in a future release.

    1. My first attempt has been with the axis label format:
    m_YAxis->setLabelFormat("%6d");
    

    That didn't work. It seems like the width modifier is disregarded.

    1. The next intuitive attempt was to connect the topmost chart signal 'plotAreaChanged' with a slot in the 2 other charts such as:
    void LinkedChart::peerPlotAreaChanged(const QRectF &pa)
    {
        if (!plotArea().isNull()) {
            setPlotArea(pa);
        }
    }
    

    While it sounds like a good idea, the result is horrific... It seems like some QChart code area aren't informed of the new plot area dimension...

    alt text

    1. I did finally manage to do what I wanted with this slot in the 2 mid and bottom charts:
    void LinkedChart::peerPlotAreaChanged(const QRectF &pa)
    {
        if (!plotArea().isNull()) {
            QMargins curMargins = margins();
            curMargins.setLeft(curMargins.left()+pa.left()-plotArea().left());
            setMargins(curMargins);
        }
    }
    

    This does what I want but at startup, the 2 charts have the time to be painted with their old margins value and you can see them adjusted some time after the startup. Probably just me who would notice but this annoys the perfectionist that I am...I might try to find a way to set correctly the margins at construction....

    JKSHJ 1 Reply Last reply
    3
    • L lano1106

      The initial issue that I had was that 3 charts placed into a QVBoxLayout, having identical X axis were not aligned because the topmost chart Y axis labels were longer than the 2 other charts:
      aligned charts

      As you can see, I have finally succeeded but in the long and hard journey to find a working way, I think that I have stumbled into a serie of small QtCharts glitches. Therefore, I am documenting here what I have observed to help you guys improving the code in a future release.

      1. My first attempt has been with the axis label format:
      m_YAxis->setLabelFormat("%6d");
      

      That didn't work. It seems like the width modifier is disregarded.

      1. The next intuitive attempt was to connect the topmost chart signal 'plotAreaChanged' with a slot in the 2 other charts such as:
      void LinkedChart::peerPlotAreaChanged(const QRectF &pa)
      {
          if (!plotArea().isNull()) {
              setPlotArea(pa);
          }
      }
      

      While it sounds like a good idea, the result is horrific... It seems like some QChart code area aren't informed of the new plot area dimension...

      alt text

      1. I did finally manage to do what I wanted with this slot in the 2 mid and bottom charts:
      void LinkedChart::peerPlotAreaChanged(const QRectF &pa)
      {
          if (!plotArea().isNull()) {
              QMargins curMargins = margins();
              curMargins.setLeft(curMargins.left()+pa.left()-plotArea().left());
              setMargins(curMargins);
          }
      }
      

      This does what I want but at startup, the 2 charts have the time to be painted with their old margins value and you can see them adjusted some time after the startup. Probably just me who would notice but this annoys the perfectionist that I am...I might try to find a way to set correctly the margins at construction....

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi @lano1106, thank you for sharing such a detailed investigation; I'm glad you found a procedure that achieves what you want (minus the visual glitch at startup). Would you be willing to post this to https://bugreports.qt.io/ ? There's a much higher chance that it gets picked up there and integrated into Qt. Posts on this forum will eventually get buried in time.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      4
      • L Offline
        L Offline
        lano1106
        wrote on last edited by lano1106
        #3

        sure will do.

        BTW, I think that having the grid/axis not resized in #2 of the OP could be related to my latest discovery in:
        https://forum.qt.io/topic/110370/issue-with-qchart-layout-when-resizing-the-parent-qchartview-qt-5-14-0

        1 Reply Last reply
        2
        • L Offline
          L Offline
          lano1106
          wrote on last edited by
          #4

          https://bugreports.qt.io/browse/QTBUG-81110

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved