Python Forum
[PyQt] QPainter issue showing black screen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] QPainter issue showing black screen
#1
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?

Attached Files

Thumbnail(s)
       
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue with GUI screen switching in Python QT5 code greenelephant 1 211 Apr-04-2024, 09:58 PM
Last Post: deanhystad
  QPixmap not updating in QGraphicsScene after using QPainter on it Leo_Red 1 1,447 Apr-15-2022, 07:09 PM
Last Post: deanhystad
  [Tkinter] showing return from button on main screen blazejwiecha 4 2,648 Nov-22-2020, 04:33 PM
Last Post: blazejwiecha
  Qpainter Error GMCobraz 6 4,344 Aug-26-2020, 06:57 AM
Last Post: GMCobraz
  [Tkinter] how to remove black area around the graph in tkinter ? NEL 1 2,280 Aug-03-2019, 01:48 PM
Last Post: NEL

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020