PDA

View Full Version : Missing action icons



ReilenBlaeyze
17th February 2006, 14:07
I'm encountering some difficulties with using KDE's default tool/menu icon schemes... I'm using KStdGuiItem::add() and KStdGuiItem::remove() to dress up some buttons but I only get a white "default icon". KStdActions on the other hand work fine in the Menus

Bojan
19th February 2006, 19:51
What version of KDE/kdelibs are you using? Also what icon theme are you using? Can you post the code where you are using these please. When you call KStdGuiItem::add(), what does hasIcon() return. You need to use one of the iconSet() methods to get the icon. Also what KStdAction works, since there is no KStdAction::add().

From quickly looking at the docs and source, this is KstdGuiItem::add():

KGuiItem KStdGuiItem::add()
{
return KGuiItem(i18n("Add"), "add");
}

which calls constructor to KGuiItem:


KGuiItem::KGuiItem( const QString &text, const QString &iconName, const QString &toolTip, const QString &whatsThis )
{
d = new KGuiItemPrivate;
d->m_text = text;
d->m_toolTip = toolTip;
d->m_whatsThis = whatsThis;
setIconName( iconName );
}

and finally setIconName():

void KGuiItem::setIconName( const QString &iconName )
{
d->m_iconName = iconName;
d->m_iconSet = QIconSet();
d->m_hasIcon = !iconName.isEmpty();
}

We can see here that the setIconName method just creates a null QIconSet. hasIcon() should return true, since iconName is not empty. To get the icon you need to use one of the iconSet() methods, which actually creates the icons using KIconLoader:


QIconSet KGuiItem::iconSet( KIcon::Group group, int size, KInstance* instance ) const
{
if( d->m_hasIcon )
{
if( !d->m_iconName.isEmpty())
{
// some caching here would(?) come handy
return instance->iconLoader()->loadIconSet( d->m_iconName, group, size, true, false );
}
else
{
return d->m_iconSet;
}
}
else
return QIconSet();
}

So really the only I can think of is that it can't find the "add" icon, at least not for the size or gorup you want. It is interesting that from 3.4 to 3.5 the only thing that really changed reagarding this was using just "add" instead of "edit_add". Dunno...

Bojan

ReilenBlaeyze
19th February 2006, 20:15
I'm using KDE 3.4.2b with Qt3.3.4
I'm using the crystalsvg icon theme

I was actually just initializing the KPushButtons with the (KStdGUIItem::KGuiItem*,QWidget*,const char*); constructor, which does seem to work since it adds text labels, but adds an empty icon...

I solved the problem for now by using KGlobal::iconLoader() to look for icons, but still don't have neat add or remove icons and settled for "ok" and "cancel" for the time being;

Bojan
19th February 2006, 21:06
Does KDE 3.4.2b mean beta? Maybe you should compare the relevant kdelibs code (kstdguiitem.cpp, kguiitem.cpp and kpushbutton.cpp) to the code in the docs for final 3.4.2. Also just out of curiosty, try passing a new KGuiItem(i18n("Add"), "add") and new KGuiItem(i18n("Add"), "edit_add"), to the KPushButton's constructor. In your icons folder, is there add.png or edit_add.png for 16x16 and 22x22? This matters, if there is edit_add.png and no add.png, and the code is ending up calling "add" as the icon name, KIconLoader will probably fail to find it. That's why you usually see same icons multiple times with different names, because they could be called differently, especially in different contexts. You said you tried KGlobal::iconLoader(), but couldn't find the icons. So it definitly looks like it can't find the icon, since otherwise, as far as I can see, the button's iconset should be null, which definitly isn't the "empty document/default/unknown" icon.

Ok, I think the problem is that Crystalsvg doesn't actually have an "add" icon. In my crystalsvg icon folder there are no "add" icons of any sort. The icon theme I use, does. It has an edit_add.png. However if I switch my icon theme to CrystalSVG, and do KStdGuiItem::add(), the loaded icon is an "add" icon from another icon theme installed on my system. My guess is that, since KIconLoader tries really hard to find an icon for you, if it can't find an icon from your current theme, it maybe looks for it in other icon themes. My best guess is that there is no "add" icon on your system at all.

Bojan

ReilenBlaeyze
20th February 2006, 13:05
I looked through the folders again and couldn't find an add or remove icon either... I guess that's been the problem all along :P