You are not logged in.

#1 2009-06-05 18:45:10

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

[SOLVED] How to Add Standard Icons to Qt Menus

Right now the "quit" button in a Qt programme I'm working on looks like this:

myprog.png

The code I'm using is,

exitAct = new QAction(tr("&Quit"), this);
exitAct->setShortcut(tr("Ctrl+Q", "Quit"));

I'd like it to have the standard quit icon I see in all my other programmes:

idealprog.png

Does anyone know how I can do this?

Last edited by tony5429 (2009-06-20 20:34:24)

Offline

#2 2009-06-05 20:01:19

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: [SOLVED] How to Add Standard Icons to Qt Menus

http://doc.trolltech.com/4.5/qaction.html#icon-prop

Every QAction has an icon property, use that to set icons.

I would recommend looking at: http://code.google.com/p/qticonloader/ for a cross-platform way of setting icons.
However, that doesn't support KDE3 so well, so I use:

action_File_New->setIcon(QtIconLoader::icon("document-new",
                                      QtIconLoader::icon("filenew",
                                         QApplication::style()->standardIcon(
                                            QStyle::SP_FileIcon))));

for File >> New

Check out http://standards.freedesktop.org/icon-n … 01s04.html for icon names

Offline

#3 2009-06-08 19:06:54

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Add Standard Icons to Qt Menus

Thanks for your suggestion, scio. Do you know how I could, rather than going with the qticonloader, simply use the kde4 standard icon for, say the File >> New button icon?

Offline

#4 2009-06-08 20:44:17

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: [SOLVED] How to Add Standard Icons to Qt Menus

1) copy all of the resources into your project in a qrc file.
2) Use http://doc.trolltech.com/4.5/qstyle.html#standardIcon

I would still highly recommend using qticonloader as it is written by a Nokia dev and will most likely be added in future versions of Qt.

Offline

#5 2009-06-09 18:50:21

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Add Standard Icons to Qt Menus

Hrm.. Well I tried out qticonloader and it worked perfectly. My only concern is qticonloader is licenced LGPL whereas my project is licenced GPL. Do you know if I can simply include qticonloader in my project without changing my licence?

Offline

#6 2009-06-09 19:14:56

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: [SOLVED] How to Add Standard Icons to Qt Menus

8    ** Commercial Usage ...
13    **
14    ** GNU Lesser General Public License Usage
15    ** Alternatively, this file may be used under the terms of the GNU Lesser
16    ** General Public License version 2.1 as published by the Free Software
17    ** Foundation and appearing in the file LICENSE.LGPL included in the
18    ** packaging of this file.  ...

22    ** In addition, as a special exception, Nokia gives you certain
23    ** additional rights. These rights are described in the Nokia Qt LGPL
24    ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
25    ** package.
26    **
27    ** GNU General Public License Usage
28    ** Alternatively, this file may be used under the terms of the GNU
29    ** General Public License version 3.0 as published by the Free Software
30    ** Foundation and appearing in the file LICENSE.GPL included in the
31    ** packaging of this file.  Please review the following information to
32    ** ensure the GNU General Public License version 3.0 requirements will be
33    ** met: http://www.gnu.org/copyleft/gpl.html.

The code can be used under any of the Qt licenses, including GPL.  Just follow GPL 3.0 rules and you will be fine.

Offline

#7 2009-06-09 19:19:02

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Add Standard Icons to Qt Menus

Hrm... so I can just drop that cpp and h file into my package and not worry about it?

Offline

#8 2009-06-10 00:33:55

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: [SOLVED] How to Add Standard Icons to Qt Menus

As long as you distribute the GPL with it like you would anyway for a GPL project.

Offline

#9 2009-06-10 00:48:22

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Add Standard Icons to Qt Menus

Okay; sounds good then. Yeah; I've got the COPYING file included in the archive already.

Offline

Board footer

Powered by FluxBB