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. Image is not displaying on pushbutton
Qt 6.11 is out! See what's new in the release blog

Image is not displaying on pushbutton

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.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.
  • P Offline
    P Offline
    pragati
    wrote on last edited by
    #1

    Hi Everyone,

    I want to add an image on push button to look as a icon, below is the code. The only problem is the app is running without a single error but the image is not being displayed on the button

    Code: (Overview.cpp)
    @
    #include "overview.h"
    #include "ui_overview.h"
    #include <QFile>
    #include <QMessageBox>

    Overview::Overview(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Overview)
    {
    ui->setupUi(this);

    QString fileName("D:/solar4000/QT/images/actual.png");
    if(QFile(fileName).exists() == false)
    QMessageBox::warning(this, "Application", "Wrong file name : " + fileName);
    else

    myButton.setIcon(QIcon(fileName));
    

    }

    Overview::~Overview()
    {
    delete ui;
    }
    @

    Thanks

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Please check out the "code wrapping possibility":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 of Qt. This makes your code better readable.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pragati
        wrote on last edited by
        #3

        I think now its readable so can be answered

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          I have closed your other topic on this same issue. Please stick to one topic per question. Double posting is not acceptable.

          What is myButton exactly? You call ui->setupUi(this), but your button does not seem to be part of your ui? I would have expected to see something like:
          @
          ui->myButton->setIcon(QIcon(filename));
          @

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pragati
            wrote on last edited by
            #5

            I did want to remove it but didn't find any option.
            myButton was the new pushbutton which I tried to add in ui through code....defined it in header file...

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              So... show us the relevant code please!

              Removing of topics can only be done by admins on this forum.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pragati
                wrote on last edited by
                #7

                Actually there is one button in ui also but i tried to put image on the button which i created through code by defining the pushbutton... I tried the one you told it worked for me...Thanks a lot

                1 Reply Last reply
                0

                • Login

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