Unsolved PySide2 cannot display image
-
I also asked this question at stackoverflow, i hope to be inspired by as many people as possible, Thanks ~
-
Hi and welcome to devnet,
Unless cat.jpg is in the same folder as where you start your python script, that won't work.
-
@SGaist Thanks for your greeting ! Yes, i put the py script and cat.jpg in the same folder, even though i pass the full path of cat.jpg, the window is still empty, please see the sreenshot (i.postimg.cc/ZqGW6xpz/image.png)
-
@weida_wang
FWIW: Try changing that guy's code so that you keep the originalQMainWindow::centralWidget()
, add aQ[HV]BoxLayout
onto it, and add yourQLabel
onto that; and maybe put in some explicit sizes while you sort it out. It's just possible you have a layout issue. Also trylabel.setScaledContents(True)
. I'm not sure why it works from PyQt but not from PySide2. -
@JonB emm, it seems not the layout issue, because
print(pixmap.isNull())
outputsTrue
, looks like something is wrong here -
@weida_wang
Then it really does sound like it's having trouble finding the file. And I still don't get why that differ from PyQt, unless you are running the PySide from a different folder. -
Did you check that the file is in fact a valid jpeg image ?
-
@SGaist
The OP claims on stackoverflow (better to have copied the post here than just reference it):If the imported package is PyQt5, it can work ! But if i replace PyQt5 with PySide2, it can't work again
:)
Which is why I want to verify he is running both from the same directory....
-
@JonB @SGaist Hi, Guys, i find the correct solution here : https://stackoverflow.com/questions/24346038/pyside-qpixmap-not-working.
Thanks for everyone's discussion ! -
@weida_wang
These links are from several years ago, for old PySide rather than new PySide2. I am surprised it is still the case: is this a bug, has it been reported on the Qt bugs site to the PySide2 people? -
Do you need to do that for a completely new installation of PySide2 ?