Artifacts when using a QPixmap
-
wrote on 30 Apr 2023, 21:26 last edited by
Hi,
When i'm creating a small pixmap I always get those little weird artifacts. It's not my first time getting them, it's also happening in every other Qt binding for python, and it's not hardware-bound since I have also been encountering this problem about a year ago before upgrading my machine. Even the simpliest piece of code can cause this issue. In other programs I've encountered even weirder issues when using QPainter (see image no.3, i'm pretty sure this isn't caused by the program itself). Despite me using PySide for a long time I've never been able to figure out why this actually happens. I've also never seen anyone else having this problem.This is the code that results in the first two artifacts:
from PySide6 import QtWidgets, QtGui import sys class MyWindow(QtWidgets.QWidget): def __init__(self): super().__init__() self.label = QtWidgets.QLabel(self) self.label.setPixmap(QtGui.QPixmap(320, 160)) layout = QtWidgets.QVBoxLayout(self) layout.addWidget(self.label) self.setLayout(layout) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = MyWindow() window.show() sys.exit(app.exec())
-
Hi,
When i'm creating a small pixmap I always get those little weird artifacts. It's not my first time getting them, it's also happening in every other Qt binding for python, and it's not hardware-bound since I have also been encountering this problem about a year ago before upgrading my machine. Even the simpliest piece of code can cause this issue. In other programs I've encountered even weirder issues when using QPainter (see image no.3, i'm pretty sure this isn't caused by the program itself). Despite me using PySide for a long time I've never been able to figure out why this actually happens. I've also never seen anyone else having this problem.This is the code that results in the first two artifacts:
from PySide6 import QtWidgets, QtGui import sys class MyWindow(QtWidgets.QWidget): def __init__(self): super().__init__() self.label = QtWidgets.QLabel(self) self.label.setPixmap(QtGui.QPixmap(320, 160)) layout = QtWidgets.QVBoxLayout(self) layout.addWidget(self.label) self.setLayout(layout) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) window = MyWindow() window.show() sys.exit(app.exec())
wrote on 1 May 2023, 06:46 last edited by@LorDawid
Since all you doself.label.setPixmap(QtGui.QPixmap(320, 160))
you do not set the pixmap's content to anything, so what do you expect? You could get anything. https://doc.qt.io/qt-6/qpixmap.html#QPixmap-1Warning: This will create a QPixmap with uninitialized data. Call fill() to fill the pixmap with an appropriate color before drawing onto it with QPainter.
-
@LorDawid
Since all you doself.label.setPixmap(QtGui.QPixmap(320, 160))
you do not set the pixmap's content to anything, so what do you expect? You could get anything. https://doc.qt.io/qt-6/qpixmap.html#QPixmap-1Warning: This will create a QPixmap with uninitialized data. Call fill() to fill the pixmap with an appropriate color before drawing onto it with QPainter.
-
@JonB Thank you, you're right. For some reason, I thought initializing QPixmap without any data would return me an empty QPixmap, because that's the case with most classes, and I was wrong. Thank you very much.
1/4