Solved change icon of pushbutton
-
Hello..I want to change the pushbutton icon when the user clicks on it.I mean like in the case of Vlc media player.When we click on pause the button,icon changes to play and vice versa.Can someone help me in this case? Thanks....
-
-
@p3c0 I did the same what you said to.But the icons(images) are not appearing.What may be the problem?
-
@abhay Did it appear first time ?
-
@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).
-
@abhay Post the code how you attempted to do it.
-
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. -
@p3c0 Yeah.path is correct and it's in a resource file.What do you mean by Qicon 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);
-
@p3c0 Yeah..I am sorry.Found this solution just now.Thanks you very much for your solution !! :)
-
@abhay Please can you share the solution.