QComboBox cannot show the icon



  • I am using Qt5.8.0 and QtCreator 4.2.1. The resource was added before. The icon cannot displayed. Only with absolute path C:/img/icon/ works. And I compile the source with 5.9.0 with QtCreator 4.3.0 without any modification. It shows the icon. Someone can tell me the reason and solution.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi( this );
        ui->comboBox->addItem( QIcon( ":/img/icon/star.png" ), "Test1" );
        ui->comboBox->addItem( QIcon( ":/img/icon/pencil.png" ), "Test2" );
        ui->comboBox->addItem( QIcon( ":/img/icon/delete.png" ), "Test3" );
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

  • Qt Champions 2016

    Hi
    If you go to the resource in the project view, find the file and right click.
    What paths is shown ?

    alt text

    Is the actual img folder located on c:/ ?



  • http://imgur.com/a/qmEY2
    alt text
    The Path is correct. Its Real Path is C:\Users...\Documents\Qt5.8.0\15_QComboBox\icon


  • Qt Champions 2016

    @king558
    Does it show a preview ?
    Path seems correct so I wonder if it really can find them

    If you click on the top resource file and select
    alt text
    (missing files)

    Does the star/delete/pencil stay?



  • @mrjj
    alt text

    Now it shows the icon, what I did is, run qmake and rebuild. Thx all for help.


  • Qt Champions 2016

    @king558
    Oh so it did not recompile it by itself :)
    Sometimes one must run qmake manually.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.