[Qt-interest] Setting the Window Icon
O'carroll, David T
david.t.o'carroll at intel.com
Tue Feb 22 13:59:36 CET 2011
Hi,
I inserted the Q_ASSERT as suggested but it never fails, even when the image doesn't show. This is the code I'm running:
QFileInfo file(“/path/to/file.png”);
if(file.exists())
{
qDebug() << “Setting window icon” << file.absoluteFilePath();
QPixmap image("/path/to/image.png");
Q_ASSERT(!image.isEmpty());
Image = image.scaled(QSize(50, 50));
qDebug() << "Dimensions: width - " << image.width() << " height - " << image.height();
QApplication::setWindowIcon(QIcon(image));
}
else
{
qDebug() << “File: “ << file.absoluteFilePath() << “ not found”;
}
And the output I get is (always):
Setting window icon /path/to/image.png
Dimensions: width - 50 height - 50
I also tried resizing the images to line up with the correct icon size (both manually and using QPixmap::scaled()) but nothing seems to work. I keep getting the same random results. If I run the code ten times it might work five but it's never the same five as the previous run.
Any help would be greatly appreciated,
Dave
-----Original Message-----
From: qt-interest-bounces+david.t.o'carroll=intel.com at qt.nokia.com [mailto:qt-interest-bounces+david.t.o'carroll=intel.com at qt.nokia.com] On Behalf Of Malyushytsky, Alex
Sent: Wednesday, February 16, 2011 6:46 PM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] Setting the Window Icon
Try to check if the file is actually a valid pixmap.
As far as I understand for QIcon to operate needs to have a valid QPixmap.
Since QIcon is basically a set of pixmaps, and is not a single pixmap
checking QIcon for nullness might not be sufficient to identify was picture read from the file
successfully.
According to documentation QIcon might be not null and still not be able to produce an image
for example if the file does not exist or cannot be read (or recognized?).
So I would suggest for testing purposes test if pixmap can be loaded from the file first.
You could add code similar to below to perform such check:
{
QString path= “/path/to/file.png”;
QPixmap pix ( path );
Q_ASSERT( !pix.isEmpty() );
}
If assert fails, QPixmap was not able to create image from file.
And QIcon will not be able to show pixmap.
If it does not, I would check sizes of the pixmaps you load, QIconEngine might be not able to scale pixmap you load to the size you need.
Alex
From: O'carroll, David T [mailto:david.t.o'carroll at intel.com]
Sent: Wednesday, February 16, 2011 1:51 AM
To: Malyushytsky, Alex; qt-interest at qt.nokia.com
Subject: RE: Setting the Window Icon
Hi,
Thanks for the reply.
I tried checking if the file existed using the QFileInfo class and it always found the file.
I also used QDir to list the contents of the directory in which all the images I need are stored and it was able to find them all.
This is the code I’m using to check for the file:
QFileInfo file(“/path/to/file.png”);
if(file.exists())
{
qDebug() << “Setting window icon”;
QApplication::setWindowIcon(QIcon(“/path/to/file.png”));
}
else
{
qDebug() << “File: “ << file.absoluteFilePath() << “ not found”;
}
This will always output “Setting window icon” and yet the icon is not always set (in fact it is quite rare that it does get set).
Seeing as the file can be read by both QFileInfo and QDir could there be a problem with QIcon?
Dave
From: qt-interest-bounces+david.t.o'carroll=intel.com at qt.nokia.com [mailto:qt-interest-bounces+david.t.o'carroll=intel.com at qt.nokia.com] On Behalf Of Malyushytsky, Alex
Sent: Tuesday, February 15, 2011 11:35 PM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] Setting the Window Icon
My guesses this is failure to find image file.
Try to use absolute path instead of relative and check if file exists.
Put some code which will notify you about path when does not.
Alex
From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of O'carroll, David T
Sent: Tuesday, February 15, 2011 6:10 AM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] Setting the Window Icon
Hi,
I am trying to integrate a demo into the Meego IVI UX. I am trying to set the window icon of an application to a different image depending on what QWidget is running. The QWidget is launched as the application starts and is passed to the application as an argument (so it only needs to be set once). Currently I am setting it in main.cpp with:
QApplication::setWindowIcon(QIcon(“/path/to/image.png”));
However, this leads to somewhat random results wherein the image is set sometimes and not others. Is there something I’m missing about QIcon (I’m used to working with QPixmap) or am I simply going about this the wrong?
Regards,
Dave
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”
“Please consider our environment before printing this email.”
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
--------------------------------------------------------------
Intel Shannon Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263
Business address: Dromore House, East Park, Shannon, Co. Clare
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
More information about the Qt-interest-old
mailing list