Solved 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; }
-
Hi
If you go to the resource in the project view, find the file and right click.
What paths is shown ?Is the actual img folder located on c:/ ?
-
http://imgur.com/a/qmEY2
The Path is correct. Its Real Path is C:\Users...\Documents\Qt5.8.0\15_QComboBox\icon -
@king558
Does it show a preview ?
Path seems correct so I wonder if it really can find themIf you click on the top resource file and select
(missing files)Does the star/delete/pencil stay?
-
Now it shows the icon, what I did is, run qmake and rebuild. Thx all for help.
-
@king558
Oh so it did not recompile it by itself :)
Sometimes one must run qmake manually.