QGraphicsItem: get pixels of drawn items



  • I want to draw a line (QLine, QLineF or QGraphicsLineItem) on a QGraphicsView. How can I get information about the pixels that are covered by the line? (Please note that the line might be dashed or have a certain width so I do not mean just the pixels in between the endpoints.) Iterating over all pixels of the whole QGraphicsView (or better the bounding rect) might take a long time. Qt should know these pixels because it has to tell the QGraphicsScene to update them.

    I use PyQt but an answer for Qt might also help me.

    Thank you!


  • Moderators

    @BlackEyedLion Hi!
    Why do you need this information?



  • @jsulm
    I need to know the color of each pixel to do some image processing calculations. Therefore I want to record the colors in a list - at the beginning for the whole image, later for those pixels that were changed by drawing the line. Of course, I can iterate over all pixels in the image and get their color but that is slow; for a 1 million pixels image it takes about 1.8 seconds on my computer. Iterating over the entries of a 1 million entries list and reading the recorded color from there takes only about 0.2 seconds. I read that the QImage.scanLine function improves the performance but I have not tried it up to now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.