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. Clipping QGraphicsItems in a QChart
QtWS25 Last Chance

Clipping QGraphicsItems in a QChart

Scheduled Pinned Locked Moved Unsolved General and Desktop
qchartqgraphicsitemclipping
3 Posts 2 Posters 713 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.
  • W Offline
    W Offline
    wombatonfire
    wrote on 17 Dec 2019, 10:36 last edited by
    #1

    Hi,

    I am using QChart for a real-time plot. The x-axis is a datetime axis, the y-axis is a value axis. As you can expect with the real-time plot, the window moves right on the x-axis ahead of time, and up/down on the y-axis as the max/min values change.

    As the window moves, the line series objects, managed by the QChart, are correctly painted inside the plotArea. But as I add custom QGraphicsItems to the scene, they can be partially painted outside the plotArea, because the scene area is bigger than the QChart's plotArea.

    An obvious solution would be to use clipping, and it worked good during my test. I've reimplemented the paint() method for my custom QGraphicsItems and used setClipRect() method on the painter with the QChart's plotArea rect. But what bothers me in this approach is that, whenever I read about clipping in the docs, it says that this operation is expensive and affects performance.

    I wonder, how expensive is it? Does clipping affects performance in some specific scenarios only, or should it be avoided in general? I've seen the warning in the docs, that it should not be used, if possible, but there is no further details.

    I also looked at the QCharts source, and I can see painter->setClipRect(clipRect) in the LineChartItem::paint(), so, I suppose, QChart is using exactly the same approach for keeping graphics objects inside the plot area. This sort of contradicts the recomendation regarding clipping in the docs, isn't it?

    If not clipping, I've also been playing with managing the custom QGraphicsItems myself and hiding them, when the item's coordinates go outside of QChart's plotArea, but this requires more code, might be more error-prone, and might not necessarilly be faster as the number of items grows.

    I would appreciate any thoughts on using clipping and/or ideas regarding alternative approaches for painting QGraphicsItems inside the QChart's plotArea.

    Regards,
    Yuri.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Dec 2019, 21:31 last edited by
      #2

      Hi,

      This is something you have to benchmark for your application.

      If it's working OK for you then just use it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        wombatonfire
        wrote on 19 Dec 2019, 19:23 last edited by
        #3

        For sure it can be measured, and I do agree with the approach "if it works fine, just use it".

        But I am still curious, why clipping is expensive in the first place, so that the warning exists in the docs? Has anyone experienced performance impact while actively using clipping for real-time chart?

        1 Reply Last reply
        0

        3/3

        19 Dec 2019, 19:23

        • Login

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