Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [SOLVED] PySide - Problem with QLabel and QPixmap
Forum Update on Monday, May 27th 2025

[SOLVED] PySide - Problem with QLabel and QPixmap

Scheduled Pinned Locked Moved Language Bindings
4 Posts 2 Posters 5.1k Views
  • 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.
  • J Offline
    J Offline
    johnmcderp
    wrote on 1 Jul 2012, 04:03 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on 2 Jul 2012, 11:31 last edited by
      #2

      Are you sure the current directory is the path where the image is located? Did you check that?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        johnmcderp
        wrote on 2 Jul 2012, 12:16 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 2 Jul 2012, 12:30 last edited by
          #4

          Great, thanks for reporting back with your solution!

          1 Reply Last reply
          0

          1/4

          1 Jul 2012, 04:03

          • Login

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