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. QGraphicsItem paint keep old content
Forum Updated to NodeBB v4.3 + New Features

QGraphicsItem paint keep old content

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.9k Views 2 Watching
  • 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
    LuGRU
    wrote on last edited by
    #1

    Hello,
    I do face a problem, well not really a problem, as this do behave correctly, with QGraphicsItem::paint() QPainter.

    Problem is that when QGraphicsItem::paint() method is invoked QPainter will clear item content.
    Work around for this is using QPixmap as "cache" but that do take memory, especially on HDPI embedded system.

    I tried various blending options, but every one of them do erase previous content.

    My question, is there a way to force QPainter in QGraphicsItem::paint() to not erase previous content, so when paint is issues with specified rectangle any call to i.e. QPainter::drawPath() will only add new content.

    What I want to achieve: drawing by moue (like in Paint) without need to use cache of any sort minimizing memory footprint and increasing drawing speed by using smallest possible clipping rect.

    Thanks for any suggestions.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you share the code you are using for the painting ?

      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
      • L Offline
        L Offline
        LuGRU
        wrote on last edited by
        #3

        It's simply call to draw 2 last elements from QPainterPath, like:

        void Item::paint(QPainter *painter,
                            const QStyleOptionGraphicsItem *option,
                            QWidget *widget)
        {
            const QPointF& p1 = path.elementAt( path.elementCount()-2);
            const QPointF& p2 = path.elementAt( path.elementCount()-1);
            
            painter->drawLine( p1, p2);
        }
        

        painter path to increase in mouseMove by lineTo( event->pos());
        Omitted checks etc.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The thing is, you are currently going against the recommendation of the paint function which state that your item should redraw itself the exact same way.

          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
          • L Offline
            L Offline
            LuGRU
            wrote on last edited by LuGRU
            #5

            Not exactly, I do call update() after new line is added to QPainterPath.
            There is also similar issue with macOS and transparency, but in that case it's other way around old content is not cleared. I do think that this could be achieved and I don't see any problem with letting developer to clear theirs item's content manually. The problem is I don't want to go as deep as patching Qt (probably view or scene classes) due to deployment problems (I do need to deploy to 3-4 OS'es so it will be pain to maintain).

            AFAIKT there is no relation between item content (human visible content) and content that is mentioned in documentation and only important parts are boundingRect() and shape() with do determine "content" size from scene point of view, rest is irrelevant and if painting is done inside item no artifact should occur.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Which version of Qt are you using by the way ?

              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
              • L Offline
                L Offline
                LuGRU
                wrote on last edited by
                #7

                Qt 5.7 msvc.

                1 Reply Last reply
                0

                • Login

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