How to set image on QPushButton ?

How to set image on QPushButton ?

Asked on December 18, 2018 in Qt.
Add Comment


  • 3 Answer(s)

    The size of the button will be correct, to reisze the icon  pixmap size:

    QPixmap pixmap("image_path");
    QIcon ButtonIcon(pixmap);
    button->setIcon(ButtonIcon);
    button->setIconSize(pixmap.rect().size());
    

     

    Answered on December 18, 2018.
    Add Comment

    Try this code:

    QPushButton *button = new QPushButton;
    button->setIcon(QIcon(":/icons/..."));
    button->setIconSize(QSize(65, 65));
    
    Answered on December 18, 2018.
    Add Comment

    The given below code is simple:

    QPixmap pixmap("image_path");
    QIcon ButtonIcon(pixmap);
    button->setIcon(ButtonIcon);
    button->setIconSize(pixmap.rect().size());
    button->setFixedSize(pixmap.rect().size());
    
    Answered on December 18, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.