![]() Registered Member ![]()
|
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:
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 ![]() |
![]() Administrator ![]()
|
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] |
![]() Registered Member ![]()
|
Well, my idea was to not use any loading at all
![]() When, for example in constructor I explicitly, add lines such as:
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? |
![]() Registered Member ![]()
|
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?
|
![]() Administrator ![]()
|
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] |
![]() Registered Member ![]()
|
Ok, thank you for reply, maybe I will use QPushButton instead.
|
![]() KDE Developer ![]()
|
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.
|
![]() KDE Developer ![]()
|
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.
![]() |
![]() Registered Member ![]()
|
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.
|
![]() Moderator ![]()
|
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 |
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft