Icon not shown on other PC - qt

im developing QT application, and im using few icons
this is my resource.qrc file
<RCC>
<qresource prefix="/new/prefix1">
<file>army-officer-icon.png</file>
<file>uac.png</file>
</qresource>
</RCC>
then i ofcourse include it in my .pro file
RESOURCES += \
resource.qrc
and here is the code which takes care of icons:
//this code is part of the mainwindow.cpp
QSystemTrayIcon *trayIcon;
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/new/prefix1/army-officer-icon.png"));
trayIcon->show();
//this code is part of the ui_mainwindow.h (generated by QT)
QLabel *label_5;
label_5 = new QLabel(centralWidget);
label_5->setObjectName(QString::fromUtf8("label_5"));
label_5->setGeometry(QRect(40, 302, 46, 21));
label_5->setPixmap(QPixmap(QString::fromUtf8(":/new/prefix1/uac.png")));
label_5->show();
So, this looks reasonable, right ?
===windows 7, developing station, QT installed
also the result effect is as i expected
i can see both icons :: tray icon & uac shield = awesome
but when i move to the other workstation, somethings strange happens
===windows XP, user work station, QT NOT installed
as u can see, the trayicon still has its own icon, but the "uac shield icon" dissapears... its very disturbing, and i really dont get it since both icons are *.png formats, i browsed a lot, and maybe it has connection with qt image plugins (althought i think that i should care about it only when my icon are *.jpeg, *.gif format), but wasnt able to make this solution works...
so any ideas are welcomed.
Thanx in advance.

Okay, ive found the solution just after ive posted this (actually , i was quite close, but i copied something with wrong path :/)
locate C:\QtSDK\Desktop\Qt\4.8.0\mingw\plugins
copy plugins/imageformats to your application folder
open main.cpp and add this line of codes
a.addLibraryPath(QCoreApplication::applicationDirPath ()+"/plugins");
compile, and have a look at your beautiful icons :)

Related

What has happened to SwingFXUtils?

I just started using JavaFX 11, and SwingFXUtils seems to be gone (or renamed?)
I tried to download it manually, but the module-system complained about import sun.awt.image.IntegerComponentRaster;, and I couldn't get it to work.
I need to convert Swing Icon to JavaFX image.
Since Java 9, SwingFXUtils has been moved to the javafx.swing module, under the package javafx.embed.swing.
See JavaFX 9 Javadoc and the new JavaFX 11 Javadoc, hosted at https://openjfx.io.
If you have any issue with your sample, make sure you are adding the proper VM options. See the samples from the getting started guide.
Probably you will need to add something like:
--module-path <path-to>/javafx-sdk-11/lib --add-modules=javafx.controls,javafx.swing
SwingFXUtils is still there if you have correctly added the javafx.swing module to your build path (see answer from José) but importing an internal class like sun.awt.image.IntegerComponentRaster is not allowed anymore.
To convert your icon you can try this:
Icon icon; // Your icon
BufferedImage image = (BufferedImage)((ImageIcon)icon).getImage();
WritableImage writable = SwingFXUtils.toFXImage(image, null);
Whether this works or not depends on how your icon was created but it is worth a try.

geting icon by name is not working

I can't get icon lookup by name to work correctly. I copied the code from Gallery examples and repeated the same configuration in my project, but it doesn't work.
This is what I did:
1.Copy icons/gallery into the directory of my own project, this is the list of files:
icons/default
icons/default/20x20#3
icons/default/20x20#3/back.png
icons/default/20x20#3/menu.png
icons/default/20x20#3/drawer.png
icons/default/20x20#4
icons/default/20x20#4/back.png
icons/default/20x20#4/menu.png
icons/default/20x20#4/drawer.png
icons/default/20x20
icons/default/20x20/back.png
icons/default/20x20/menu.png
icons/default/20x20/drawer.png
icons/default/index.theme
icons/default/20x20#2
icons/default/20x20#2/back.png
icons/default/20x20#2/menu.png
icons/default/20x20#2/drawer.png
2.Added index.theme file into theme directory:
[Icon Theme]
Name=default
Comment=Qt Quick Controls 2 Gallery Example Icon Theme
Directories=20x20,20x20#2,20x20#3,20x20#4
[20x20]
Size=20
Type=Fixed
[20x20#2]
Size=20
Scale=2
Type=Fixed
[20x20#3]
Size=20
Scale=3
Type=Fixed
[20x20#4]
Size=20
Scale=4
Type=Fixed
3.Added corresponding lines to main.cpp, to enable icons, this is the code:
QGuiApplication::setApplicationName("MyApp");
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QIcon::setThemeName("default");
QQuickStyle::setStyle("Material");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
In a QML file I use the icon this way:
ToolButton {
icon.name: "menu"
}
If I lookup by URL, it works fine:
ToolButton {
icon.source: "qrc:/icons/default/20x20/menu.png"
}
So, what could be the reason of why lookup by name doesn't work and how to debug this ?
EDIT:
After Mitch's answer I found that icon's weren't working because the ":/icons" entry in the icon's path wasn't the first one.
So, this code DOESN'T work:
QIcon::setThemeName("default");
QStringList list;
list<<":/icons";
list<<"/usr/share/icons";
QIcon::setThemeSearchPaths(list);
However, this cdoe DOES work:
QIcon::setThemeName("default");
QStringList list;
list<<":/icons";
list<<"/usr/share/icons";
QIcon::setThemeSearchPaths(list);
To make it work you only need to make the path where your icons are located, first entry in list.
But maybe it is a bug, I am using Qt 5.11
If the list of things you did is exhaustive, then you missed a step:
Traditionally, only Linux and UNIX support icon themes on the platform level, but it is possible to bundle a compliant icon theme in an application to use themed icons on any platform.
The default icon theme search paths depend on the platform. On Linux and UNIX, the search path will use the XDG_DATA_DIRS environment variable if available. All platforms have the resource directory :/icons as a fallback. Custom icon theme search paths can be set with QIcon::setThemeSearchPaths().
The following example bundles an icon theme called mytheme into the application's resources using Qt's resource system.
<RCC>
<qresource prefix="/">
<file>icons/mytheme/index.theme</file>
<file>icons/mytheme/32x32/myicon.png</file>
<file>icons/mytheme/32x32#2/myicon.png</file>
</qresource>
</RCC>
After creating that file, you also need to add it to your .pro.

Weid layout when loading SWF with QWebView

After a bit of research I wasn't really able to understand why this happens.
In a nutshell, I'm calling QWebView and feeding a .swf into it and it works. However it goes out of its frame/layout, and I'm not sure why.
For a representation, see:
As you may see, the dark greyish rectangle is where QWebView was placed, however the .swf going into it is represented out of it in the top left corner.
How to recreate this problem:
I literally just placed a QWebView using the designer, added all the includes needed etc. and added 3 lines of code to mainwindow.cpp :
QWebSettings *settings = ui->webView->settings();
settings->setAttribute(QWebSettings::PluginsEnabled, true);
ui->webView->load(QUrl("http://www.w3schools.com/html/bookmark.swf"));
I also tried opening an html file with the .swf wrapped in it, but the same problem occurs.
Am I doing something wrong? Is it a known bug? Thanks in advance.
Apparently this is a known bug with Qt, will be fixed next release.
Source: https://bugreports.qt-project.org/browse/QTBUG-33053
What I did to fix was basically compile QT again with the fix included.

PyQt - Error while setting QLineEdit background from image

I searched all over the internet for a solution for this, but found nothing.
Basicly I have a QLineEdit name 'le' (inside a class) whose background I want to set as an image. Using the code bellow, i get the error "Could not parse stylesheet of widget 0x1867580" and the image is not dispalyed.
self.le = QtGui.QLineEdit(self)
self.le.move(300,300)
self.le.setFrame(False)
self.le.setFixedWidth(100)
self.le.setStyleSheet("background: url:(Try.png)")
The Try.png image is a 100x20 px image, so it was supposed to fit that particular QLineEdit.
Does anyone have a clue about what might be going on?
Many thanks in advance,
Miguel
Try
self.ls.setStyleSheet("background-image: url(Try.png);")
but Try.png must be in folder from which Qt app started. Unless it is a resource, then
self.ls.setStyleSheet("background-image: url(:/images/try);")
where images is name of resource group
<qresource prefix="/images">
<file alias="try">Try.png</file>
</qresource>
then the image will be compiled into the app.

Ubunto12.04-Gnome3 -- Show icon in alt-tab menu using .desktop file

After Googling for hours, I didn't find any answer for the following issue and so glad if anyone could help.
I use Ubuntu 12.04 LTS with Gnome-shell 3.4.1. Consider the following simple program in file $HOME/a.py which I have made it executable:
#!/usr/bin/env python
import gtk
w = gtk.Window()
w.set_size_request(250, 150)
w.set_title("test program")
w.connect('destroy', lambda x: gtk.main_quit())
w.show_all()
gtk.main()
I've used MenuLibre to define a_run0.desktop in $HOME/.local/share/applications as below:
[Desktop Entry]
Version=1.0
Type=Application
Name=a_run
Comment=comm.
Icon=applications-development
Exec=/home/vsop/a.py
Path=
Terminal=false
StartupNotify=true
Categories=
Name[en_US]=a_run
Comment[en_US]=comm.
I made a_run0.desktop to be executable and I see a file named “a_run” in $HOME/.local/share/applications with proper icon (Icon=applications-development
). Running the program and using alt-tab, the icon is also shown in alt-tab menu quite well.
The question is, when I copy “a_run” file (actually a_run0.desktop) to $HOME/Desktop, the file is shown with correct icon in Desktop but after running it, the icon shown in alt-tab menu is changed to unknown-red-circle-icon with the name of original file “A.py” underneath.
What is made this problem and how can I see the defined-icon (in .desktop file) correctly in the alt-tab menu after running the program from $HOME/Desktop?
Try to add icon to your window using python and gtk. I think that icon in .desktop file only specify how .desktop file is shown in system not application.
Certainly in more recent versions of Gnome shell (I'm using 3.14.1) the entry Icon should point to the actual icon you want to use, e.g
Icon=/home/vsop/a_icon.xpm

Resources