When I create the "Command link button" (QCommandLinkButton) it has relatively nice green arrow icon.
I would like to see what other nice icons can I choose. When I try to change the icon, [Theme] appears instead of path or some GUI selection dialog:
I also noticed the context menu:
When I click Set icon from theme, again expecting some GUI selection list, I get just a text field:
What I was imagining:
Where's the list of icons from which the green arrow was taken?
QIcon::fromTheme works under specific conditions.
If it can find it in the QIcon::themeSearchPaths() for the QIcon::themeName()
If the desired icon isn't there, Qt Designer won't be able to do any of the from theme, named icons.
But... if you check your target system for the theme search paths and set the theme name, you are more likely to have success.
Example
On linux, I wanted to get a plus and a minus icon.
I found list-add.png and list-remove.png fit the bill.
https://github.com/GNOME/adwaita-icon-theme/tree/master/Adwaita/16x16/actions
http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
I did a locate on my system and found these:
/usr/share/icons/gnome/16x16/actions/list-add.png
...
/usr/share/icons/gnome/32x32/actions/list-add.png
/usr/share/icons/gnome/scalable/actions/list-add.svg
/usr/share/icons/oxygen/16x16/actions/list-add.png
...
Forcing with fallback icon in QIcon::fromTheme
Find the icon on the filesystem:
ui->toolButton->setIcon(QIcon::fromTheme("list-add",
QIcon("/usr/share/icons/gnome/16x16/actions/list-add.png")));
Find the icon in the qt resource system...
Add the icon in a qrc file in your build, then reference it's path.
ui->toolButton->setIcon(QIcon::fromTheme("list-add",
QIcon(":/list-add.png")));
Overriding the current icon theme
qDebug() << "themeSearchPaths:" << QIcon::themeSearchPaths() << QIcon::themeName();
// themeSearchPaths: ("/usr/local/share/icons", "/usr/share/icons", ":/icons") "hicolor"
The default theme for the system, and for the target deployment machine, likely didn't have the icons in it I wanted... but the gnome or oxygen icon desktop theme installed would almost always have it...
QIcon::setThemeName("oxygen");
Note that you won't see the preview in Qt Designer necessarily because it doesn't set the theme until runtime of your code.
The gnome icon library has 1100+ icons in it. Here is one list:
https://gist.github.com/peteristhegreat/c0ca6e1a57e5d4b9cd0bb1d7b3be1d6a
This works as long as you know what themes are available on the target system.
The list from freedesktop.org has 286 icons listed.
Use icons included in Qt
Just like #peppe pointed out, Qt includes 70 standard icons, too.
widget->setIcon(widget->style()->standardIcon(QStyle::SP_BrowserReload));
http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum
Conclusion
Using a stock library on your target system is probably the fastest. Using the Qt built-ins is fast to figure out and use, but is fairly limited. Using a resource file is probably the most robust method, and gives unlimited options on what icon to use.
Be sure to pick a standard icon pack, and think about licensing and attributions, and some other things like that.
And there is no shortage of icons available online:
https://www.quora.com/What-is-the-best-icon-library
https://www.google.com/search?q=open+source+icon+library
Hope that helps.
I don't think that's the function you want to use. The "theme" name there corresponds to the QIcon::fromTheme functionality, which uses icons named according to the FDO specification
http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
And they're not really supported on non-FDO platforms (Windows, Mac, ...) unless you deploy your own theme files.
Now some stock icons are shipped with Qt itself; I don't know how to set them from Designer, but from code you can use QStyle::standardIcon:
widget->setIcon(widget->style()->standardIcon(QStyle::SP_BrowserReload));
If the icon you need is not provided by Qt, you'll need to ship it. In that case the Resource System is a convenient way to bundle it alongside your executable.
Last, but not least, from a UX point of view you should consider using QToolButtons unless you're really building a Vista-like wizard.
Related
I'm playing with Mingw and embedding Icons. I add a single Icon by using windres and linking it in at compile time.
TRAY_ICON ICON "np.ico"
The Icon for the executable shows as the linked one, and opening the file with CFF explorer or similar tools show the Icon in the resource section.
When loading the Icon from within the application I use LoadIcon like below:
LoadIcon(GetModuleHandle(NULL), "TRAY_ICON");
Which works as expected and I can use the Icon for whatever. When looking at other executables I can see multiple Icons in the resources however. These are similar and are only different in size.
With multiple Icons present in the resource section, how does Windows decide which one to use when viewing the file in explorer or similar?
How are specific Icons selected when specifying a given Icon group?
K, so solved both, just forgot to post an answer here.
Windows uses the first icon group for the program icon.
Icon files can contain multiple images. Use the Linux imagemagic package to merge them. Windows decides which one to use based on size.
I'm working on a Qt UI that will run on a touchscreen. At some point it will be useful to select files, in (probably) a QFileDialog.
But little icons on a QFileDialog leads to a terrible touch-user experience, I'd like them to be bigger, so the user doesn't get crazy trying to navigate in the filesystem.
Actually, I'm searching documentation to see if there is a way through css, but haven't seen yet which target/propery to use.
Given the doc of QFileDialog class:
QFileDialog::Detail 0 Displays an icon, a name, and details for each item in the directory.
QFileDialog::List 1 Displays only an icon and a name for each item in the directory.
You can't set icon size this way. I recommend you to set a custom icon provider on the QFileDialog.
OS X 10.7.5, Eclipse 4.3 Kepler build ID 20130919-0819, Java 1.7.0_51
I'm following along the Vogel tutorial, and I have (another) problem. I've added a toolbar as described in the tutorial, but no icons appear on the toolbar. The toolbar itself appears, but it is empty. If I click in the empty space where the icon should be, the handler is called as expected. I can add an icon file to my project, and have my HandledToolItem point to it, and in that case the icon is visible, and operates as expected.
Should I expect default icons to appear automatically? Do I have to import or include standard Eclipse icons somehow? Or do I have to add each icon manually (I rather doubt this is the case.)
Thanks, gary
You can add Icons via the platform-notation, e.g. platform:/plugin/de.myplugin.ui/icons/icon.gif.
Using this way, you can also access eclipse-build-in-icons.
See this blogpost: http://codeandme.blogspot.co.at/2012/07/reusing-platform-images.html for a plugin to browse the available plugins.
I am trying to chance the icon of the exe file created native bundling of javafx packaging but it still contains the default icon. Please suggest
primaryStage.getIcons().add(FileUtility.loadImage("icon.png"));
did not help, it only changes the title bar and task bar icon.
The ico file still gets generated and icon of the exe files remains the default one
I also tried to assign an icon in the project properties-> Deployment-> icon but did not help
I believe I have encountered the same issue and the solution is described in the following thread.
As a side note - neither specifying your icon in the build.xml file or via the project's options in the deployment section is going to work thus far, but it seems to be fixed in the upcoming release of 7u10.
I added response here How to set custom icon for javafx native package icon on Windows and thinks it is the same issue you started out with. However you seem to have moved on, but others might find it interesting...
I added src/main/deploy/package/windows/myapp.ico there and it finally worked :)
For you:
Create src/main/deploy/package/windows/ folder
Add icon with name ${project.build.finalName}.ico
Run mvn jfx:build-native
I haven't played with it extensively - just got it to work and wanted to share. So if you want to use icon with different name, I don't know how. Not yet at least. The ... section in the config section seems to be for webstart, so I haven't been using it. Hope you get it to work!
Answered at How to set custom icon for javafx native package icon on Windows
I'm trying to display a "warning" icon next to a QLineEdit if it contains invalid data. I was trying to use QStyle::standardIcon(QStyle::SP_MessageBoxWarning) to get a standard pixmap and place it inside a QLabel, and in some cases this seems to work. When running Gnome the icon is displayed correctly, but when running under KDE no icon is shown. I assume that the warning icon is simply not included in the style used under KDE.
What is the preferred way to display a "standard" warning icon in Qt? Does there exist some list which shows which icons are included in every style? How can I get an icon from a style that I know includes the warning icon?
The last time I had a similar problem, I found this Qt labs discussion useful. It informed me that QIcon now (since 4.6 I believe) has a QIcon::fromTheme function that allows you to load an icon based on the Freedesktop.org Icon Naming Specification, and in addition provide a fallback icon to be used if the current theme does not have the icon in question.
What I did was then to include some very basic icons for use as fallback, and in general specify icons only by their Freedesktop names. This gave a theme-consistent look almost always, and the program still worked in cases where people were missing icons.
As for the warning icon, I'm guessing/hoping that every theme must have the one named "dialog-warning", and that it's what you're looking for.
I hope this helps.
Edit: Oh and, in case you don't know, it can be useful to look at for example the Tango icon set to get a rough idea of what the Freedesktop names correspond to (although it is of course theme-dependent).
Qt does bundle a number of images that are resources that you can use in your own code. These images are a superset of those available via standardIcon() You may want to verify that the particular image is included in the versions of Qt you're targeting.
The end result could look like the following:
QPixmap pixmap(":/trolltech/styles/commonstyle/images/up-128.png");
// use pixmap as needed
For anyone who wants to know how to do this in a Windows environment you can:
Create a qLabel in your custom class, and then in the constructor of that class create a QIcon with the style you want, convert it into a pixmap and use the QLabel::setPixmap() function to apply it to the one you created:
QIcon icon = style()->standardIcon(QStyle::SP_MessageBoxWarning); //or
//whatever icon you choose
QPixmap pixmap = icon.pixmap(QSize(60, 60));
ui->iconLabel->setPixmap(pixmap);
ui->iconLabel->setScaledContents(true); //you can set this to fill the
//dimensions of your qLabel if you wish.