[solved]Pushbutton and Icons
-
wrote on 21 Sept 2011, 07:10 last edited by
I got problems when I'm going to change an icon on a button.
the button gets blank with no Icon:
My code@fileName.append("\Icons\NBStartup.png");
ui->btnNB->setIcon(QIcon(fileName));
@
My platform is Linux Debian.
[Edit: Please use @-tags for code snippets /Vass] -
wrote on 21 Sept 2011, 07:39 last edited by
So... after fileName.append, what does filename contain exactly? Is that really the path to your icon file?
-
wrote on 21 Sept 2011, 07:54 last edited by
In my opinion there is a problem with the file or the path to it. You can add a check to verify that the file of the icon exists:
@
QFile myIcon( fileName );
if( true == myIcon.exists() )
{
ui->btnNB->setIcon(QIcon(fileName));
}
else
{
qDebug() << "File does not exists!";
}
@ -
wrote on 21 Sept 2011, 07:55 last edited by
It's solved
filename.append("/Icons/NBStartup.png")
No backslash ;It's working
-
wrote on 21 Sept 2011, 12:03 last edited by
From the documentation about QFile:
QFile expects the file separator to be '/' regardless of operating system. The use of other separators (e.g., '') is not supported.I believe it is a bad idea to hard code '/' anyway, you should use Qdir::separator instead.
-
wrote on 21 Sept 2011, 15:17 last edited by
[quote author="fluca1978" date="1316606616"]
I believe it is a bad idea to hard code '/' anyway, you should use Qdir::separator instead.[/quote]No, hard coding '/' is indeed the proper way. From the QDir::separator() documentation:
bq. You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators().
1/6