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. What's the best Area to draw QRects and QPixmaps to?

What's the best Area to draw QRects and QPixmaps to?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.5k 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.
  • M Offline
    M Offline
    mrousavy
    wrote on last edited by
    #1

    I'm building a tool which will take a Screenshot of the whole screen, and then open a new fullscreen window which just displays the screenshot.

    Now I want to draw a bunch of rectangles onto that window. (but not onto the actual pixmap!)

    I've been experimenting with a QGraphicsView and QGraphicsScene, until I found out that everytime I add a new item (QGraphicsScene::addRect()) the QGraphicsScene tries to make room for that via collision detection, looks like this at first:

    0_1518549157922_Screenshot1.png

    but after adding some rectangles the image moves:

    0_1518549106971_Capture.PNG

    So I am searching for a way to efficiently draw rectangles onto the screen (and be able to remove them again) in Qt Widgets.

    Thanks!

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ofmrew
      wrote on last edited by
      #2

      In sounds like you want to do something similar to double buffering: draw the pixmap and then draw the graphical objects. To remove the graphical objects, just redraw the pixmap. I use that approach for rubberband lines and ruberband rectangles.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrousavy
        wrote on last edited by
        #3

        @ofmrew said in What's the best Area to draw QRects and QPixmaps to?:

        In sounds like you want to do something similar to double buffering: draw the pixmap and then draw the graphical objects. To remove the graphical objects, just redraw the pixmap. I use that approach for rubberband lines and ruberband rectangles.

        I like that idea, how do I do that?

        O 1 Reply Last reply
        0
        • M mrousavy

          @ofmrew said in What's the best Area to draw QRects and QPixmaps to?:

          In sounds like you want to do something similar to double buffering: draw the pixmap and then draw the graphical objects. To remove the graphical objects, just redraw the pixmap. I use that approach for rubberband lines and ruberband rectangles.

          I like that idea, how do I do that?

          O Offline
          O Offline
          ofmrew
          wrote on last edited by
          #4

          @mrousavy Try this: 1. Create pixmap. 2. In paintEvent() draw the pixmap. 3. Continuing in paintEvent() draw your rectangle, etc. That is it. If you are using QtCreator, you will need to create a canvas class that is a subclass of QWidget. Drag-and-Drop a Widget onto the UI and then promote it to your canvas class. The paintEvent() is add to the canvas class.

          M 1 Reply Last reply
          0
          • O ofmrew

            @mrousavy Try this: 1. Create pixmap. 2. In paintEvent() draw the pixmap. 3. Continuing in paintEvent() draw your rectangle, etc. That is it. If you are using QtCreator, you will need to create a canvas class that is a subclass of QWidget. Drag-and-Drop a Widget onto the UI and then promote it to your canvas class. The paintEvent() is add to the canvas class.

            M Offline
            M Offline
            mrousavy
            wrote on last edited by
            #5

            @ofmrew said in What's the best Area to draw QRects and QPixmaps to?:

            @mrousavy Try this: 1. Create pixmap. 2. In paintEvent() draw the pixmap. 3. Continuing in paintEvent() draw your rectangle, etc. That is it. If you are using QtCreator, you will need to create a canvas class that is a subclass of QWidget. Drag-and-Drop a Widget onto the UI and then promote it to your canvas class. The paintEvent() is add to the canvas class.

            But then I'll be redrawing the whole QPixmap everytime I move the mouse, that's very expensive isn't it..?

            O 1 Reply Last reply
            0
            • M mrousavy

              @ofmrew said in What's the best Area to draw QRects and QPixmaps to?:

              @mrousavy Try this: 1. Create pixmap. 2. In paintEvent() draw the pixmap. 3. Continuing in paintEvent() draw your rectangle, etc. That is it. If you are using QtCreator, you will need to create a canvas class that is a subclass of QWidget. Drag-and-Drop a Widget onto the UI and then promote it to your canvas class. The paintEvent() is add to the canvas class.

              But then I'll be redrawing the whole QPixmap everytime I move the mouse, that's very expensive isn't it..?

              O Offline
              O Offline
              ofmrew
              wrote on last edited by
              #6

              @mrousavy Absolutely not, I did this back in the 80386 days, it is a BitBlit or just a byte copy operations, unless there is a size mismatch , but even then it is trivial. Do you need an example or do you have it?

              M 1 Reply Last reply
              0
              • O ofmrew

                @mrousavy Absolutely not, I did this back in the 80386 days, it is a BitBlit or just a byte copy operations, unless there is a size mismatch , but even then it is trivial. Do you need an example or do you have it?

                M Offline
                M Offline
                mrousavy
                wrote on last edited by
                #7

                @ofmrew said in What's the best Area to draw QRects and QPixmaps to?:

                @mrousavy Absolutely not, I did this back in the 80386 days, it is a BitBlit or just a byte copy operations, unless there is a size mismatch , but even then it is trivial. Do you need an example or do you have it?

                I think I've got it but it's really lagging as soon as I draw it on screens with sizes like 2560x1440 - My approach before was way faster :/

                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