Skip to content Skip to sidebar Skip to footer

Draw Over Image In A Qlabel With Pyqt5

I want to draw over image with my mouse. I simplified the problem by this code. When i uncomment the line 31 the code doesn't work. My goal is to draw over the image i want to sele

Solution 1:

Do not draw inside a widget outside of the paintEvent(). This is not supported by Qt.

You may draw on a QImage or QPixmap instead, and then in paintEvent() of your widget, draw that image. Images can be initialized with all pixels transparent as well, if you like to composite several images (background+drawing) instead of drawing on the background directly.

Solution 2:

I think the way is best for you is using QLabel to view the image and OpenCV to draw over the image by those events. The issue is you will need to refresh the image after each change. I did that in this project project, it is working, but it might be better to if you use QT library.

Post a Comment for "Draw Over Image In A Qlabel With Pyqt5"