This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KDE app and Resources file

Tags: icons, resources icons, resources icons, resources
(comma "," separated)
sigma
Registered Member
Posts
5
Karma
0
OS

KDE app and Resources file

Mon Aug 30, 2010 9:30 am
Hello,

I'm developing kde 4 application - for designing widget I'm using Qt Designer. For managing icons I want to use resources file. My application uses some kde classes and some Qt classes, for development I use KDevelop and for building CMake.

I have problem with loading icons. I googled about building Qt-Applications in CMake and in CMakeFileList I've added lines:

Code: Select all
find_package(KDE4 REQUIRED)
find_package(Qt4 REQUIRED)

include (KDE4Defaults)
include (${QT_USE_FILE})
ADD_DEFINITIONS (${QT_DEFINITIONS})

include_directories( ${KDE4_INCLUDES} ${QT_INCLUDES} )

SET(app_RESOURCES resources.qrc)
qt4_add_resources(app_RESOURCES_RCC ${app_RESOURCES})
kde4_add_executable(app ${app_SRCS} ${app_RESOURCES_RCC})
target_link_libraries(app ${KDE4_KDEUI_LIBS} ${QT_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})


But no icons are loaded. When I use qmake, resources file works fine, but I have to use CMake... any idea what am I doing wrong? Can KDE application use resources file? Or I have to load them at runtime? I will appreciate any help :)
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: KDE app and Resources file

Tue Aug 31, 2010 4:20 am
Which class are you using to load resources? The KDE KIcon class may not support Qt resources, as it primarily deals with on disk icons.

http://www.qtcentre.org/wiki/index.php? ... with_CMake


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
sigma
Registered Member
Posts
5
Karma
0
OS

Re: KDE app and Resources file

Tue Aug 31, 2010 7:28 am
Well, my idea was to not use any loading at all :) - I have resource file, in UI files there are references to each icon e.g. ":/pref/name.png" and also binary file qrc_resources.rxx with all icons is generated. As I design widget in Qt designer, I have all icons nicely put on buttons. Nevertheless, as application is executed, no icon is loaded.

When, for example in constructor I explicitly, add lines such as:
Code: Select all
kpushbutton->setIcon(KIcon(":/pref/name.png"));


It works fine, icon appears, but I thought that it should be enough to set those icons only once, in UI file... now each time icon have changed I will have to change it in both places - cpp file and UI file. I tried that method from the link - to build Qt project in cmake, but still no success. It appears that settings from UI about icons are not read.

I wonder if I do something wrong, or maybe I cannot use this approach when using mix of KDE and Qt classes... What is the most standard way to manage icons for KDE applications? Should it be done in code?
sigma
Registered Member
Posts
5
Karma
0
OS

Re: KDE app and Resources file

Tue Aug 31, 2010 8:14 am
I've just checked - when I change KPushButton to QPushButton, then everything works perfectly. Is there a way to keep using K-equivalent and to have possibility of managing icons this way? Or only way is to do it by hand in code?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: KDE app and Resources file

Wed Sep 01, 2010 7:08 am
KIcon does not support usage of Qt resources. You will need to use QIcon.

eg: kpushbutton->setIcon( QIcon(":/path/to/resource") )


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
sigma
Registered Member
Posts
5
Karma
0
OS

Re: KDE app and Resources file

Wed Sep 01, 2010 7:14 am
Ok, thank you for reply, maybe I will use QPushButton instead.
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

Re: KDE app and Resources file

Sun Sep 05, 2010 2:02 pm
As far as I know, KIcon refers to icon by name, not by path. It does that to refer to an icon in a way that makes it possible to use different themes, i.e. the filename will stay the same but the path will change.

What you can try to do is to refer to the icon by name as if you would have it installed, but add the resource path to the list of icon paths known to KStandardDirs.

KStandardDirs provides KDE applications with lists of paths (and convenience methods) to look for certain type of resources, such as icons, config, etc.
Since it is almost certainly using QDir/QFile internally, it should be able to look into resource paths as well.

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
The User
KDE Developer
Posts
647
Karma
0
OS

Re: KDE app and Resources file

Sat Sep 11, 2010 5:15 pm
The KDE-widgets work with QIcon, too, so you do not need QPushButton or anything like that. But I would first try the KStandardDirs-suggestion. ;)
sigma
Registered Member
Posts
5
Karma
0
OS

Re: KDE app and Resources file

Sat Sep 11, 2010 5:37 pm
Hey, I'm pretty lazy... I wish I could click those icons from designer (in Qt Designer) and to use resource file. I know I can load everything for example in constructor, it works. But project is quite big: many, many icons, without text, so we need to have icons displayed while designing and of course to have icons while running. But it happens that what I set in designer, does not take effect in runtime. To have icons I have to load them manually in some method. But I don't like this because in UI file they are already defined, so that thing is doubled. But when QPushButtons are used, everything is ok.
User avatar
jstaniek
Moderator
Posts
1027
Karma
2
OS

Re: KDE app and Resources file

Thu Feb 16, 2012 10:39 pm
Old thread but hope this helps:

Designer in Qt 4.8 has QIcon::fromTheme() support, so you just set the icon name in designer, and have it load KDE icons. (a hint from Christoph Feck)

This means also KDE app's icons can be loaded if they are installed in in places visible for the KIcon system, i.e. via cmake command kde4_install_icons(${DATA_INSTALL_DIR}/**APPNAME**/icons).

The news: http://lists.qt.nokia.com/pipermail/qt- ... 07704.html

See also: https://bugreports.qt-project.org/browse/QTBUG-7777


Best regards,
Jarosław Staniek
• Qt Certified Specialist
KEXI - Open Source Visual DB Apps Builder
• Request a feature or fix for KEXI here
May I help you? Please mention your app's version and OS when asking for help


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft