Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Artifacts when using a QPixmap
Forum Updated to NodeBB v4.3 + New Features

Artifacts when using a QPixmap

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 422 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LorDawid
    wrote on last edited by
    #1

    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())
    
    

    248140d7-ed86-4e42-b386-8067553362b8-image.png
    358ade62-1e59-42a7-af04-ae84b7d8e8a2-image.png
    629cb492-5efc-40a7-8555-6bbb0285d152-image.png

    JonBJ 1 Reply Last reply
    0
    • L LorDawid

      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())
      
      

      248140d7-ed86-4e42-b386-8067553362b8-image.png
      358ade62-1e59-42a7-af04-ae84b7d8e8a2-image.png
      629cb492-5efc-40a7-8555-6bbb0285d152-image.png

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @LorDawid
      Since all you do self.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-1

      Warning: This will create a QPixmap with uninitialized data. Call fill() to fill the pixmap with an appropriate color before drawing onto it with QPainter.

      L 1 Reply Last reply
      2
      • JonBJ JonB

        @LorDawid
        Since all you do self.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-1

        Warning: This will create a QPixmap with uninitialized data. Call fill() to fill the pixmap with an appropriate color before drawing onto it with QPainter.

        L Offline
        L Offline
        LorDawid
        wrote on last edited by
        #3

        @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.

        JonBJ 1 Reply Last reply
        0
        • L LorDawid

          @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.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @LorDawid
          QPixmap::fill() is probably an "expensive" operation (pixmap could be "large"), and also a waste if you then do your own fill or set your own pixmap, so that is presumably why they leave it uninitialized.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved