Search code examples
qtqt5qpixmap

QPixmap parse ico image file that does't show


I use QPixmap parse ico image file and set qpixmap object to QLabel whit setPixmap function,but doesn't show ico image.

ico_label_ = new QLabel(this);
ico_label_->move(100, 100);
QPixmap pixmap(":/client/test.ico");
Q_ASSERT(!pixmap.isNull());
ico_label_->setPixmap(pixmap);

With Q_ASSERT checking pixmap is valid. please help me how to do that ico image file can show on QLabel

Since stackoverflow can't upload ico file and the ico file see test ico file


Solution

  • The icon you've provided seems to be not valid. (At least the file I've downloaded from the Drop-Box)

    This project demonstrates that .ico in Qt4/5 work (tested with both)

    https://github.com/vheinitz/QIconTest

    • Show Icon 1: attempts to display your icon (fails)
    • Show Icon 2: attempts to display other icon (works)

    Often issues with not displayed icons (or other image formats) occurs due to missing (or not found at run-time) plugins.

    Make sure, you include required plugins in your installation and set the path at the run time to the plugin location e.g.:

    qApp->addLibraryPath(qApp->applicationDirPath()+"/plugins");