[solved]Pushbutton and Icons
-
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] -
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!";
}
@ -
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.
-
[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().