Results 1 to 5 of 5

Thread: QIcon Directory Location

  1. #1
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default QIcon Directory Location

    Hi,
    I created a ui form in designer, this form has a QListView and other QIcon.
    I am not using a resource file .rc. The files are in a directory on my filesystem. So, I browse to the icon I want and it shows up in the form (/resources/images/icons). I save the finished ui form by 'viewing code' then save to my windows folder, as ui_form.h
    This is my project directory structure.
    myproject/bin -- qt application binary
    myproject/resources/images/icons/
    myproject/windows
    myproject/scenes. ..etc.
    myproject/ui forms/form1.ui
    myproject/ui forms/form2.ui ..etc

    My executable is in the bin directory. I changed my .pro file to put the binary in this directory.
    The problem is that if the binary is in the bin folder, the icon locations SHOULD be "../resources/images/icons". However the designer is saving them as QIcon ("/resources/images/icons"). So they don't show up and I have to change the form manually. (if I save the ui forms in the binary folder it is ok). I know this is probably a basic setup question I am overlooking something.
    Thanks for your replies.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QIcon Directory Location

    I suggest using .qrc (not .rc) file as it gives you your resources compiled into your executable file so you dont need to care about where your icon is. But if you really dont want that solution (which is very good IMO) and you are creating your ui files with Designer, I think that it will insert the actual path to those icon files, and not the path where your exec would be after compilation, so, as you noticed, you have to change your paths manually. Or there's maybe another way, which I dont know. I always use .qrc with icons, as the icon file is about 1KB large (png icon) so it's not a big difference if your exec is 50KB or 51KB. And you save a lot of time, when you dont have to care about paths.

  3. #3
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QIcon Directory Location

    Thanks for the reply..
    I don't want to use .qrc because I want the exe to be separate so the icons can be easily changed by the end user. (i.e via upload usb, net, etc).

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QIcon Directory Location

    How about using QDir::setSearchPaths(). Of course Qt Designer is not able to show the icons if you pass icon names like "icons:undo.png" but it gives great flexibility in the code to switch the search path on the fly ie. you'll get a basic theming support for free.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    QbelcorT (28th January 2009)

  6. #5
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QIcon Directory Location

    Thanks JP.
    This does work, I've changed my backgrounds/sounds/icons to follow this format, seems much easier.
    However for my ui form icons I think the best method would be for me to create the icons outside the form in my window. Doing so will allow me to implement the same method for them.
    This code is in the designer. I cannot easily access the icon variable from my window because it is not public. Only the listWidget variable is public. If I can somehow set the icons of my listWidget outside the ui form that would be much easier OR I can just use this code outside my ui form (in my window).
    Qt Code:
    1. listWidget = new QListWidget(systemProgram);
    2. QIcon icon;
    3. icon.addPixmap(QPixmap(QString::fromUtf8("../resources/images/exec.png")), QIcon::Normal, QIcon::Off);
    4. QListWidgetItem *__listItem = new QListWidgetItem(listWidget);
    5. __listItem->setIcon(icon);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. install help nedded.
    By aj2903 in forum Installation and Deployment
    Replies: 9
    Last Post: 13th November 2008, 08:57
  2. Make error with Qt Jambi 4.3.2_01
    By pamalite in forum Installation and Deployment
    Replies: 0
    Last Post: 22nd November 2007, 13:05
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21
  4. error in compiling qtopia.....
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 11th January 2007, 10:10
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 13:54

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.