Forum

Author Topic: Show a picture in PySide2 Qt Gui  (Read 5254 times)

mcstieg

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Show a picture in PySide2 Qt Gui
« on: August 26, 2021, 07:36:16 AM »
Hello everybody,

can someone please tell me how to show a small picture in a GUI?
I made some GUIs with PySide2 but I don't know how to load a fixed picture to them.

It must have to do with QPixmap ?!

Code: [Select]
from PySide2 import QtCore, QtGui, QtWidgets

class ref_korr_gui(QtWidgets.QDialog):

    def __init__ (self, parent):
        QtWidgets.QDialog.__init__(self, parent)
        doc = Metashape.app.document
        chunk = doc.chunk   
        self.setWindowTitle("Ref.-Korr.")
               
        image_path = "D:\Dropbox\Showreel\16 Markerplatten\Zusatzsoftware\Korrektur.jpg"

        picture = QtGui.QPixmap(image_path)
        self.label = QtWidgets.QLabel()
        self.label.setPixmap(picture)
        self.label.setGeometry(QtCore.QRect(10, 40, picture.width(), picture.height()))
        ...
        layout = QtWidgets.QGridLayout()
        layout.addWidget(self.label,           11,1)
        self.setLayout(layout)
        self.exec()

If I print(picture.width()) it is "0" ... But why?
« Last Edit: August 26, 2021, 07:46:37 AM by mcstieg »

mcstieg

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Show a picture in PySide2 Qt Gui
« Reply #1 on: August 26, 2021, 08:05:08 AM »
Found the mistake ... path had \ instead of /.
Thanks!