Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use IMAGE AS BUTTON?



  • I want to insert an IMAGE, and use that particular IMAGE AS BUTTON.

    Using only the code option and not use the DESIGN PART.

    eg: The play and pause button which appear as inverted triangle and a square respectively , in a video file etc.

    Could I get help with same.



  • Hi,

    You can use QPushButton, and add the image we have setIcon() method

    QPushbutton *button = new QPushbutton;
    button->setIcon(QIcon("<imagePath>"));

    Add images in the resource file, as it will relative path, dont provide absolute path.
    Based on the condition, change the image in Button, for play and pause.

    Thanks,



  • Hi,

    You can use QPushButton, and add the image we have setIcon() method

    QPushbutton *button = new QPushbutton;
    button->setIcon(QIcon("<imagePath>"));

    Add images in the resource file, as it will relative path, dont provide absolute path.
    Based on the condition, change the image in Button, for play and pause.

    Thanks,



  • @Pradeep-Kumar Thanks Sir, Now its working,
    I was giving absolute path.



  • Hi @adityatrikha08 ,

    Glad u got the solution, happy coding.

    Thanks,


Log in to reply