Results 1 to 3 of 3

Thread: How do I Use Icons in My Program?

  1. #1
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I Use Icons in My Program?

    I'm trying to figure out how to show an icon on a QPushButton. Hope you can help me out.

    I set the icon (member of a resource file) using Qt Designer, and it shows up fine in Preview mode but not in my compiled program (the icon won't show up at all). Following are the relevant lines from the .ui file:

    Qt Code:
    1. public:
    2. QPushButton *btnPrs; // Parse button
    3. ...
    4.  
    5. void setupUi(QWidget *frmWindow)
    6. {
    7. ...
    8. btnPrs = new QPushButton(frmWindow);
    9. btnPrs->setObjectName(QString::fromUtf8("btnPrs"));
    10. QIcon icon;
    11. icon.addFile(QString::fromUtf8(":/Go.png"), QSize(), QIcon::Normal, QIcon::Off);
    12. btnPrs->setIcon(icon);
    13. btnPrs->setFlat(false);
    14. ...
    To copy to clipboard, switch view to plain text mode 
    Some more facts:
    I've added
    Qt Code:
    1. Q_INIT_RESOURCE(resrc);
    To copy to clipboard, switch view to plain text mode 
    before QApplication instantiation in main.cpp.

    I've also added
    Qt Code:
    1. RESOURCES += ./Resources/resrc.qrc
    To copy to clipboard, switch view to plain text mode 
    to the project file.

    The project's directory tree is as follows:

    /ParserTest/ (containing all the .h, .ui, .cpp files and a .pro file)
    - ./Resources/ (containing all .ico and .png files and the resrc.qrc file)
    - ./Etc/ (Not used yet)

    I'm not using prefixes in the .qrc.

    This is on 32-bit Windows, Qt 4.7.2 (pre-compiled binaries) + MinGW 4.4.0 + Qt Creator 2.1.0.

    This problem also occurs with *.ico files.

    What else should I do?


    Added after 1 5 minutes:


    If I move the icon loading affairs from the form constructor -- formClass::setupUi() -- to my application window constructor, the icon shows up. But what could be the problem? Is it possible to keep icon loading codes in setupUi() to keep my codes well-organized?
    Last edited by Chase; 24th April 2011 at 11:53.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I Use Icons in My Program?

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Chase (25th April 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I Use Icons in My Program?

    Sorry, I no longer keep the old files. My bad...

    I decided to create a new project and pasted all codes from the old one (except UI and project files). I then rebuilt the entire UI's in Qt Creator and made some adjustments to the project file. Everything's been working fine now. All icon-loading codes are now back to where they belong -- setupUi().

    Thanks for trying to help.
    Last edited by Chase; 25th April 2011 at 11:43.

Similar Threads

  1. Replies: 0
    Last Post: 20th August 2010, 13:45
  2. Replies: 1
    Last Post: 30th April 2010, 13:25
  3. running external console program by gui program
    By alireza.mixedreality in forum Qt Programming
    Replies: 4
    Last Post: 24th April 2010, 18:05
  4. a program to start another program.
    By zakis in forum Qt Programming
    Replies: 4
    Last Post: 17th December 2009, 19:25
  5. Replies: 7
    Last Post: 19th January 2008, 15:29

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.