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

KAction: How to set user icon ?

Tags: kaction, kicon kaction, kicon kaction, kicon
(comma "," separated)
lagergfn
Registered Member
Posts
3
Karma
0
OS

KAction: How to set user icon ?

Sat Jul 31, 2010 12:45 pm
I am trying to use KAction with a selfmade application specific icons.
All other stuff works but the selfmade icons are not shown correctly.

My first attempt goes like this:

Code: Select all
KAction* clearAction = new KAction(this);
clearAction->setText(i18n("&Clear1"));
clearAction->setIcon(KIcon("document-new"));
clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
actionCollection()->addAction("clear", clearAction);
connect(clearAction, SIGNAL(triggered(bool)),
   m_uiListBox_p, SLOT(findAgain()));


which works fine and uses the document-new.png icon which is shipped
with KDE.

My next attempt is:

Code: Select all
KAction* clearAction2 = new KAction(this);
clearAction2->setText(i18n("&Clear2"));
clearAction2->setIcon(KIcon("document-newXX"));
clearAction2->setShortcut(Qt::CTRL + Qt::Key_V);
actionCollection()->addAction("clear2", clearAction2);
connect(clearAction2, SIGNAL(triggered(bool)),
      m_uiListBox_p, SLOT(clearBuf()));


with selfmade icons called document-newXX.png copied to the locations
as below. (document-newXX.png are just a plain copies of the document-new.png icons of appropriate size)

Code: Select all
lagergfn@linux-w9sj:/usr/share/icons> find . -name document-new*.*
./gnome/16x16/actions/document-new.png
./gnome/22x22/actions/document-new.png
./gnome/scalable/actions/document-new.svg
./gnome/32x32/actions/document-new.png
./gnome/24x24/actions/document-new.png
./oxygen/16x16/actions/document-new.png
./oxygen/16x16/actions/document-newXX.png
./oxygen/48x48/actions/document-new.png
./oxygen/48x48/actions/document-newXX.png
./oxygen/22x22/actions/document-new.png
./oxygen/22x22/actions/document-newXX.png
./oxygen/32x32/actions/document-new.png
./oxygen/32x32/actions/document-newXX.png


but in this case the icon is not displayed correctly.
A different icon is shown.
In the "Settings -> Configure Toolbar" dialog I can change
the icon but I can select only those shipped with KDE although
document-newXX.png is present in the "Configure Toolbar"
icon selection dialog.

What do I do wrong ???

I am using KDE 4.3.5

Thank you very much



By the way:

Code: Select all
QString iconpath =
   KIconLoader::global()->iconPath( "document-new",
        KIconLoader::Toolbar, false );
KMessageBox::information( this, iconpath );
   
iconpath =
KIconLoader::global()->iconPath( "document-newXX", 
             KIconLoader::Toolbar, false );
KMessageBox::information( this, iconpath );



returns correct path for both icons.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: KAction: How to set user icon ?

Sat Jul 31, 2010 10:53 pm
Have you tried naming the icon "document-new-myapp" and naming the *.png files appropriately? The XDG specification requires that certain behaviours are observed, which may be causing problems. Also, try to keep everything lower cased.


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

Re: KAction: How to set user icon ?

Sat Aug 07, 2010 10:38 am
I tried everything lowercase, I tried myapp-iconname.png. I also tried document-new-myapp.png, nothing works. I put everything under /usr/share/icons/oxygen/actions/.. and also in the application's working directory. I also did some tries with QIcon::addFile(...).

The behaviour changes slightly, but in general I do not get any reasonable icon on the button.

I am starting to get frustrated because I cannot implement my application without custom button icons.

Any further ideas ???
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

Re: KAction: How to set user icon ?

Sat Aug 07, 2010 12:44 pm
It is probably a mixture of correct filenaming and in source reference, as well as using the correct CMake macro.

For example look at KJotsWidget, line 243.
It is referencing an application specific icon "edit-delete-page".

Code: Select all
action->setIcon( KIcon( "edit-delete-page" ) );

http://websvn.kde.org/trunk/KDE/kdepim/ ... iew=markup

The icon files are in the application's icon directory and named like this
Code: Select all
ox16-actions-edit-delete-page.png
ox22-actions-edit-delete-page.png
ox32-actions-edit-delete-page.png
ox48-actions-edit-delete-page.png
oxsc-actions-edit-delete-page.svgz

http://websvn.kde.org/trunk/KDE/kdepim/kjots/icons/

So assuming that "edit-delete-page" is the choosable name part, an action icon obviously needs an "actions" prefix and a prefix containing size and a theme hint.

(the KJots directory also has hicolor versions for the app icon itself)

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
lagergfn
Registered Member
Posts
3
Karma
0
OS

Re: KAction: How to set user icon ?

Sun Aug 08, 2010 9:09 am
Now it works !!!

After editing CMakeLists.txt and adjusting the icon naming
everything works as expected.

Thank you for your help.

Cheers


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]