Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PNG map in QLabel won't show
Forum Updated to NodeBB v4.3 + New Features

PNG map in QLabel won't show

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 449 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.
  • R Offline
    R Offline
    Rangerguy128
    wrote on last edited by
    #1

    Hello, I'm kinda new in PyQt development, so I've been using QT Desginer to create some quick UIs for my app. However, I've been encountering an error. In the main ui, there's a map png that has 5 radio buttons over it when seen on QT Designer. However, as I ran the code on VS Code, the map picture is missing but the radio buttons were still there, and I'm not sure what's causing the problem.

    Here's the error that the system is sending: Could not create pixmap from :\newPrefix\Test\App\image\map.png

    For visualization, here's what it should look like:
    28e7703b-3a24-43cf-89c8-86cabba860d0-image.png

    And instead this is what the end result looks like after running it through VS Code:
    b5862317-1706-441b-bfe7-9f974fa64c98-image.png

    Curiously enough, when I exported the UI model to VS Code, there was one line that was left unresolved which was this:
    import image qt_rc

    I'm not sure if this has anything to do with the map image or not, as it came automatically with the code. Any help is appreciated.

    JoeCFDJ 1 Reply Last reply
    0
    • R Rangerguy128

      Hello, I'm kinda new in PyQt development, so I've been using QT Desginer to create some quick UIs for my app. However, I've been encountering an error. In the main ui, there's a map png that has 5 radio buttons over it when seen on QT Designer. However, as I ran the code on VS Code, the map picture is missing but the radio buttons were still there, and I'm not sure what's causing the problem.

      Here's the error that the system is sending: Could not create pixmap from :\newPrefix\Test\App\image\map.png

      For visualization, here's what it should look like:
      28e7703b-3a24-43cf-89c8-86cabba860d0-image.png

      And instead this is what the end result looks like after running it through VS Code:
      b5862317-1706-441b-bfe7-9f974fa64c98-image.png

      Curiously enough, when I exported the UI model to VS Code, there was one line that was left unresolved which was this:
      import image qt_rc

      I'm not sure if this has anything to do with the map image or not, as it came automatically with the code. Any help is appreciated.

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @Rangerguy128 show the code how you set the png

      R 1 Reply Last reply
      0
      • Ronel_qtmasterR Offline
        Ronel_qtmasterR Offline
        Ronel_qtmaster
        wrote on last edited by
        #3

        @Rangerguy128 i think you should use QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);

        EXemple
        QString path = "image.png";
        QImage img;
        img.load(path);

        ui->myLabel->setPixmap(QPixmap::fromImage(img));

        JoeCFDJ 1 Reply Last reply
        1
        • Ronel_qtmasterR Ronel_qtmaster

          @Rangerguy128 i think you should use QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);

          EXemple
          QString path = "image.png";
          QImage img;
          img.load(path);

          ui->myLabel->setPixmap(QPixmap::fromImage(img));

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @Ronel_qtmaster
          what is the output of ui->myLabel->size()?
          myLabel->resize(pixmap.width(), pixmap.height());

          or scale pixmap to the size of myLabel

          Ronel_qtmasterR 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @Ronel_qtmaster
            what is the output of ui->myLabel->size()?
            myLabel->resize(pixmap.width(), pixmap.height());

            or scale pixmap to the size of myLabel

            Ronel_qtmasterR Offline
            Ronel_qtmasterR Offline
            Ronel_qtmaster
            wrote on last edited by
            #5

            @JoeCFD i think he just wanted to load the image

            1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @Rangerguy128 show the code how you set the png

              R Offline
              R Offline
              Rangerguy128
              wrote on last edited by
              #6

              @JoeCFD Nevermind, I finally found a workaround. Apperantly, I should have inserted the image in the widget/label through this:
              0a612eeb-4db4-4dcd-ab95-a8aba3bca9c2-image.png

              Before, I was adding the background image by Change Stylesheet > Add Resources. Not sure why that didn't work but adding the image on the pixmap property did, though.

              However, it's still generating this line of code (located in 175), even after fixing it and I'm still not sure what to do with it:
              e6fcb850-39bc-4be9-8eeb-01726e63ef41-image.png

              1 Reply Last reply
              0

              • Login

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