change icon of pushbutton
-
-
@p3c0 Are you asking if it appared after changing my code?No.When I did it through stylesheet it appeared but icon is not changing and image is not looking good.When I click on it,it goes somewhat black and when I further click on it,it goes white(I mean color of the button).I think it is due to checkable property.But the images are not appearing at all(for the first time also).
-
void SimplePlayer::on_fullscreen_clicked(bool checked) { QIcon *ico = new QIcon(); ico->addPixmap(QPixmap("icons/icons/full_in.png"),QIcon::Normal,QIcon::On); ico->addPixmap(QPixmap("icons/icons/full_out.png"),QIcon::Normal,QIcon::Off); ui->fullscreen->setIcon(*ico); ui->fullscreen->setCheckable(true); }
This is my fullscreen function.I am using ui designer for buttons.
-
@abhay Are you sure the path is correct
icons/icons
?
Is it in a resource file ?
Btw. you can avoid creating icon on heap. -
@abhay So if it is in a resource file then you need to prepend colon with the proper prefix. For eg.
:/pix.png
. Here the prefix is/
What do you mean by Qicon on heap?
Using
new
to create the instance. Alternatively you can do this:QIcon ico; ico.addPixmap(QPixmap(":/icons/icons/full_in.png"),QIcon::Normal,QIcon::On); ui->fullscreen->setIcon(ico);
-
@abhay So if it is in a resource file then you need to prepend colon with the proper prefix. For eg.
:/pix.png
. Here the prefix is/
What do you mean by Qicon on heap?
Using
new
to create the instance. Alternatively you can do this:QIcon ico; ico.addPixmap(QPixmap(":/icons/icons/full_in.png"),QIcon::Normal,QIcon::On); ui->fullscreen->setIcon(ico);
-
@p3c0 Yeah..I am sorry.Found this solution just now.Thanks you very much for your solution !! :)