PDA

View Full Version : The problem of paint() function in Qgraphicsitem?



tom_1
14th January 2021, 15:36
I want to make a function of drawing image content after pressing the mouse. You can draw color and transparent channels

1:The painter parameter in the paint() function can only display images, but not the contents of the drawing process. So I created a new painter to draw the process.

2:The whole process of the mouse drawing is very slow and stuck

3:image size: 10000 * 10000

python code:




# show image
painter.drawPixmap(0, 0, self.__display)

# draw image
self.painter = QPainter()

self.painter.begin(self.__transparent)
radialGrad = QRadialGradient(self.pos, 50)
radialGrad.setColorAt(0, QColor(255, 0, 255, 255))
radialGrad.setColorAt(1, QColor(255, 0, 255, 0))
brush = QBrush(radialGrad)
self.painter.setBrush(brush)
self.painter.setPen(Qt.NoPen)
self.painter.drawEllipse(self.pos, 50, 50)
self.painter.end()

self.painter.begin(self.__display)
if self.__painterMode is 0: # Draw color on image
self.painter.drawImage(0, 0, self.__image)
self.painter.setCompositionMode(QPainter.Compositi onMode_SourceAtop)
self.painter.drawImage(0, 0, self.__transparent)
elif self.__painterMode is 1: # Draw alpha on image
self.painter.drawImage(0, 0, self.__image)
self.painter.setCompositionMode(QPainter.Compositi onMode_DestinationOut)
self.painter.drawImage(0, 0, self.__transparent)

self.painter.end()
self.update()

d_stranz
14th January 2021, 20:43
1:The painter parameter in the paint() function can only display images, but not the contents of the drawing process. So I created a new painter to draw the process.

I have no idea what you mean by "draw the process".


The whole process of the mouse drawing is very slow and stuck
image size: 10000 * 10000


What do you expect? You apparently have two images, each of them with 100 million pixels, and you are using an interpreted language to draw them. Of course it will be slow.

And if by "mouse drawing" you mean that you are updating the image with every mouse move, then of course it will deadly slow in any programming language.

You should consider using a QPainterPath to capture the mouse movements instead of setting individual pixels, which is what I think you are doing.