QClipboard corrupted image PySide6
-
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):

Image pasted from the clipboard into the app (With corrupted pixels(?)/visual bug(?)) (bottom left, red green and blue pixels):

(I can't even save that image because windows says it's corrupted).
What should I do to fix it? -
Hi,
What are you getting in your clipboard data exactly ? (Mime type, etc)
-
@SGaist clipboard.mimeData().formats() returns application/x-qt-image
-
On which version of Windows does it happen ?
-
@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())