Python Forum
[PyQt] QPainter issue showing black screen - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyQt] QPainter issue showing black screen (/thread-26587.html)



QPainter issue showing black screen - mart79 - May-06-2020

Hi,

I have the following code which I want to use to display a figure constructed out of circles.

import sys
from PySide2 import QtGui, QtWidgets

class MainWindow(QtWidgets.QDialog):
    def __init__(self):
        super().__init__()

        self.label = QtWidgets.QLabel()
        canvas = QtGui.QPixmap(400, 300)
        self.label.setPixmap(canvas)

        self.layout = QtWidgets.QVBoxLayout()

        self.layout.addWidget(self.label)
        self.setLayout(self.layout)
        self.draw_something()

    def draw_something(self):
        painter = QtGui.QPainter(self.label.pixmap())
        painter.drawPoint(200, 150)
        painter.end()

app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
However, the example shows a nice dot in the middle, see attachment (Example window.png). Whereas I get a black screen, see attachment (Error.png).
Does anyone know what is causing the problem?