Results 1 to 5 of 5

Thread: showing icons - setPixmap problem

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default showing icons - setPixmap problem

    Hello!

    I've got problem with showing icons. I've read code from program where icons were used (on buttons or just somewhere on window). I've wrote code (based on that program):

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. logoLabel = new QLabel(this);
    8. logoLabel->setPixmap(QPixmap(":/images/icon1.png"));
    9. ui->layout->addWidget(logoLabel);
    10.  
    11. button = new QPushButton;
    12. button->setIcon(QIcon(":/images/icon2.png"));
    13. button->setIconSize(QSize(48, 48));
    14. button->setFixedSize(150, 60);
    15. ui->layout->addWidget(button);
    16. }
    To copy to clipboard, switch view to plain text mode 

    but nothing shows. No icons (button is 'empty'). Images are in directory images/ where my source code is. What I'm doing wrong?

    thanks in advance
    best regards
    Tomasz
    Last edited by Tomasz; 21st July 2010 at 12:07.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: showing icons - setPixmap problem

    ":/foo" means that the image is in the Qt Resource System. Either give an absolute path, a correct relative path or the best: use the resource system. You will find a good explanation in the docs.

  3. The following user says thank you to Lykurg for this useful post:

    Tomasz (22nd July 2010)

  4. #3
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: showing icons - setPixmap problem

    Thank a lot! I've created resource file, and now it works fine!

    best regards
    Tomasz

  5. #4
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: showing icons - setPixmap problem

    I need to refresh that thread.
    Since You've told me I'm using resource files. But sometimes I need to do to read graphics from files to put it for example into QLabel? With resource files it's easy, but sometimes I have a lot of files in one resource file, and binary is very big.

    thanks in advance
    best regards
    Tomasz

  6. #5
    Join Date
    Feb 2010
    Location
    Poland
    Posts
    27
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: showing icons - setPixmap problem

    just type the path without ":/" on the begining - then a graphics will be reading from files

Similar Threads

  1. Action Icons not showing when running app
    By jimmydean101 in forum Newbie
    Replies: 4
    Last Post: 14th February 2011, 15:35
  2. Problem showing QTableView
    By weaver4 in forum Qt Programming
    Replies: 6
    Last Post: 23rd November 2009, 13:42
  3. What's the problem with setPixmap?
    By yagabey in forum Qt Programming
    Replies: 4
    Last Post: 21st November 2008, 16:34
  4. Problem showing raw images
    By wkit23 in forum Qt Programming
    Replies: 5
    Last Post: 8th September 2006, 13:33
  5. svg icons not showing up
    By ePharaoh in forum Qt Programming
    Replies: 6
    Last Post: 6th April 2006, 15:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.