[SOLVED] PySide - Problem with QLabel and QPixmap
-
I'm trying to make a QLabel display an picture using QLabel.setPixmap(QPixmap). My code is as follows:
@self.imageLabel = QLabel("No image available")
if not self.imageLabel.setPixmap(QPixmap("./placeholder.png")):
print 'No pixmap set!'@As you can see I put a little debugging message when the QLabel sets the pixmap so that I know whenever it was successful or not. And it returns 0 all the time, which is a problem because that means the image won't be displayed. The image file I'm trying to load (placeholder.png) is in the same directory as my source code so I just used the current directory ("./") as its filepath.
I'm thinking of using a QGraphicsView just to display the image but I think it's completely unnecessary and I'm trying to keep my code clean and minimal.
Any help would be appreciated, thanks in advance.
-
Your reply gave me a really important hint, thanks! I am running my app through a main.py file that's located in the root directory of my project. The code snippet I gave above was part of a file in a sub-directory inside the project that also contains the image file. I did not know that when I specified the directory "./", Python used the directory of main.py as the current directory, rather than the directory where the file holding the GUI code is located.
I put the image file in the root directory of my project and it worked. This has been a silly mistake for me, but I'm leaving the answer here in case someone stumbles across the same problem and decides to Google for a solution.