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. QClipboard corrupted image PySide6
Forum Updated to NodeBB v4.3 + New Features

QClipboard corrupted image PySide6

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 2 Posters 675 Views 1 Watching
  • 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.
  • WysciguvvkaW Offline
    WysciguvvkaW Offline
    Wysciguvvka
    wrote on last edited by Wysciguvvka
    #1

    Hi, when pasting an image copied from Windows snipping tool into the application clipboard, returned image has some corrupted(?) pixels. However, when I paste an image from a copied file (i. e. jpg file) returned image is not corrupted.

    Code:

            md = clipboard.mimeData()
            if md.hasImage():
                img = QImage(md.imageData())
                if not img.isNull():
                    image = ImageQt.fromqimage(img)
                    image.show()
    

    Image copied from windows snipping tool (before pasting):
    83db54a3-2fc7-4e85-a6a3-57dafdb56f7e-image.png
    Image pasted from the clipboard into the app (With corrupted pixels(?)/visual bug(?)) (bottom left, red green and blue pixels):
    444a436f-832c-4019-a653-94f2a40a537d-image.png
    (I can't even save that image because windows says it's corrupted).
    What should I do to fix it?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What are you getting in your clipboard data exactly ? (Mime type, etc)

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      WysciguvvkaW 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What are you getting in your clipboard data exactly ? (Mime type, etc)

        WysciguvvkaW Offline
        WysciguvvkaW Offline
        Wysciguvvka
        wrote on last edited by
        #3

        @SGaist clipboard.mimeData().formats() returns application/x-qt-image

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          On which version of Windows does it happen ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          WysciguvvkaW 1 Reply Last reply
          0
          • SGaistS SGaist

            On which version of Windows does it happen ?

            WysciguvvkaW Offline
            WysciguvvkaW Offline
            Wysciguvvka
            wrote on last edited by Wysciguvvka
            #5

            @SGaist said in QClipboard corrupted image PySide6:

            On which version of Windows does it happen ?

            Tested on Windows 10 Home 21H2 19044.1706 and Windows 10 Education 21H1 19043.1706

            Also, sample code to run and test that issue
            (For Windows: Snipping tool -> new -> select small screen fragment (for better visibility) -> ctrl+v into the application)

            from PySide6 import QtGui
            from PySide6.QtGui import QKeyEvent
            from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
            from PIL import ImageQt
            
            
            class TestWidget(QWidget):
               def __init__(self, parent=None, *args, **kwargs) -> None:
                   super(TestWidget, self).__init__(parent=parent, *args, **kwargs)
                   self.setFocus()
            
               def keyPressEvent(self, event: QKeyEvent) -> None:
                   super().keyPressEvent(event)
                   if event.matches(QtGui.QKeySequence.Paste):
                       md = QApplication.clipboard().mimeData()
                       if md.hasImage() and md.imageData():
                           image = ImageQt.fromqimage(md.imageData())
                           image.show()
            
            
            class UI(QMainWindow):
               def __init__(self, *args, **kwargs) -> None:
                   super(UI, self).__init__(*args, **kwargs)
                   self.ui = TestWidget(self)
                   self.setCentralWidget(self.ui)
            
            
            if __name__ == "__main__":
               import sys
               app = QApplication(sys.argv)
               ui = UI()
               ui.show()
               sys.exit(app.exec())
            
            1 Reply Last reply
            0

            • Login

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