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. Owner-draw QGraphicsItem Problem
Forum Update on Monday, May 27th 2025

Owner-draw QGraphicsItem Problem

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.9k 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.
  • D Offline
    D Offline
    Dashi
    wrote on last edited by
    #1

    Hi,

    I have to draw a custom graphics item on QGraphicsView, but the problem is APIs of QPainter are not sufficient for me to draw the item. So I create a QPixmap which is as large as the viewport, and draw my item on the QPixmap, then draw the QPixmap by calling QPainter::drawPixmap(). But this way is inefficient and need much more memory.

    Is there any way to improve? Can I get the pixel buffer of the QGraphicsView and draw on it directly when QGraphicsItem::paint() is called?

    BTW: I use raster graphics engine.

    Thank you!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Dashi,

      what is missing in the QPainter API? And how do you paint on the QPixmap then? Afaik, you can't access the pixel buffer directly.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dashi
        wrote on last edited by
        #3

        Hi Gerolf,

        I have some 2d NURBS curves, what I need to do is draw those curves, and fill the area enclosed. I have a function to calculate the color of each pixel in the area to be filled, so I cannot use QBrush directly.

        Thanks!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You need to use QImage to draw on pixel level.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            and the pixmap / image could be of the size of the graphics item, needn't be of graphics view

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dashi
              wrote on last edited by
              #6

              Hi Andre and Gerolf, thank you both!

              But the problem is: If the view is zoomed in, the item itself may be much bigger than the view...

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                And that is a problem because...?

                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