PNG map in QLabel won't show
-
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:
And instead this is what the end result looks like after running it through VS Code:
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_rcI'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.
-
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:
And instead this is what the end result looks like after running it through VS Code:
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_rcI'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.
@Rangerguy128 show the code how you set the png
-
@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));
-
@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));
@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_qtmaster
what is the output of ui->myLabel->size()?
myLabel->resize(pixmap.width(), pixmap.height());or scale pixmap to the size of myLabel
@JoeCFD i think he just wanted to load the image
-
@Rangerguy128 show the code how you set the png
@JoeCFD Nevermind, I finally found a workaround. Apperantly, I should have inserted the image in the widget/label through this:
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: