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. QComboBox cannot show the icon
Forum Updated to NodeBB v4.3 + New Features

QComboBox cannot show the icon

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.7k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    king558
    wrote on last edited by
    #1

    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;
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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:/ ?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        king558
        wrote on last edited by king558
        #3

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

        mrjjM 1 Reply Last reply
        0
        • K king558

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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?

          K 1 Reply Last reply
          0
          • mrjjM mrjj

            @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?

            K Offline
            K Offline
            king558
            wrote on last edited by
            #5

            @mrjj
            alt text

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

            mrjjM 1 Reply Last reply
            0
            • K king558

              @mrjj
              alt text

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              1 Reply Last reply
              1

              • Login

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