Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. set qicon to qpushbutton

set qicon to qpushbutton

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 6.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i'm trying to set an icon to qpushbutton, and the image for the icon is in the same directory as this source file, but it won't show up on the button. however, if i put the image in the root directory and specify the full path for it, say "C:\\1.png", the image will show up.

    why is this? and how can i set an icon from current directory (or say, one directory above)? i've tried "./1.png" which didn't work.

    thanks.

    #include <QApplication>
    #include <QPushButton>
    #include <QIcon>
    
    int main(int argc, char **argv) {
    
        QApplication app(argc, argv);
    
        QIcon icon("1.png");
        
        QPushButton button;
        button.setIcon(icon);
        button.show();
    
        return app.exec();
    }
    
    1 Reply Last reply
    0
    • L.GogsL Offline
      L.GogsL Offline
      L.Gogs
      wrote on last edited by
      #2

      Hi..

      You must add your png in resource file and then insert url in brackets.

          QIcon icon(":/new/ok.png");
          QPushButton *button = new QPushButton(this);
          button->setIcon(icon);
          button->show();
      
      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved