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. How to undraw a QPainterPath?
Forum Updated to NodeBB v4.3 + New Features

How to undraw a QPainterPath?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.2k Views 3 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.
  • S Offline
    S Offline
    Snorkelbuckle
    wrote on last edited by
    #1

    I can see from the Qt docs and examples on how to use QPainter::drawPath(), but how do I "undraw" a path when I want to remove it from the display area of the widget without repainting the entire widget?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arsinte_andrei
      wrote on last edited by
      #2

      what you want is impossible - the painting event is just doing that painting everything again. you have 2 options

      1. most simple - paint everything again without that portion of the path
      2. paint the background colour on the same path (blend the path with the background together - like that you have the impression that has been deleted)
      3. this is more like 1 but depending on your application, so basically imagine that you are doing a 3d or 2d cad app where you have the walls of the room - if the user moves one wall what you are doing is just deleting the last object and just paint a new one with the coordinates from starting point to the mouse coordinates
      1 Reply Last reply
      1
      • S Offline
        S Offline
        Snorkelbuckle
        wrote on last edited by
        #3

        Is there a way to paint only a small region of the screen to improve painting speed? It has been long time since I have worked with painting, so I remember vaguely with win32 that you could mark a smaller region for painting and then of course in the code you re-paint only that region needing an update. Is there something similar in Qt? Also, I'm coming from a WPF/UWP background and in that framework I would basically create a "UserControl" (QWidget) that just draw the arrow I need onto a Canvas allowing free positioning, no layout enforcement and the UserControl would be responsible to repaint itself, and if I want to remove it from the "Canvas" it is simple as removing it from a collection of "Children". I hope that makes sense to you. I'm struggling to do the same in Qt.

        so basically I envision that I should be able to specify a minimal rectangular region that contains the path element and then repaint only that area.

        Or perhaps I need to implement this differently? Do I just use a QWidget and is there sometime similar to WPF/UWP "Canvas" object in Qt that I should be using? As it is now, I have a custom QWidget which I use all the required drawing functions to display what I need to display during paintEvent.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #4

          @Snorkelbuckle said in How to undraw a QPainterPath?:

          Is there a way to paint only a small region of the screen to improve painting speed?

          Look at this QPainter methods:
          setClipRect(), setClipPath(), and setClipRegion().

          I need onto a Canvas allowing free positioning,

          Something like QGraphicsView and QGraphicScene ?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Snorkelbuckle
            wrote on last edited by
            #5

            @mpergand, thanks for that!

            It looks like I need to use QGraphicsView and QGraphicsScene. These two come the closest to what I'm used to with UWP. In terms of UWP, with these I can add a QPainterPath (or other shapes) to the QGraphicsScene's "children" collection and it is drawn automatically and then I can remove the QPainterPath simply with the removeItem() method and it is removed from the display once I delete the removed item.

            This is good, I can work with this.

            As a side note, whether or not it actually utilizes region clipping during repaint operations, I don't know (I suspect it does since it seems pretty snappy with the load I put on it during testing). But I don't really care, I can handle the overhead since I was really looking for a better way to handle the add and remove of custom shapes from the painting area.

            Thanks!

            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