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. Able to add image file in Qt Design, but image not visible at runtime. Bug?

Able to add image file in Qt Design, but image not visible at runtime. Bug?

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 6 Posters 7.4k Views
  • 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.
  • T Offline
    T Offline
    Thug
    wrote on 27 Feb 2019, 05:26 last edited by Thug 3 Apr 2019, 00:55
    #1

    Hi, I'm not a programmer and is new to Qt, checking out if Qt is suitable for GUI design.
    Using free Qt Creator 4.8.1 (based on Qt 5.12.1), on Win 10.

    I can add a PNG image of a wrench, pls see screenshot below.
    0_1551243110051_471ca088-19ab-4951-bbe4-8122137a890d-image.png

    Problem is during Runtime, it is not visible.
    0_1551243242668_91c0ad59-5148-4bbf-b386-10713a245c85-image.png

    I read on other posts to try this "Clean, Run qmake, Run". It didn't work for me.

    I saw another post about adding image file as Resource, so I added Resource.
    0_1551243570561_4de4ab55-a661-4e77-b960-54c6de652fbc-image.png

    Then I try to add the image as a Resource, using "Choose Resource" option (see screenshot below). When I clicked on "Choose Resource", the program freezes, all buttons becomes non interactive. I have to press ESC for the program to "snap out of it." So this is an dead end for me.
    0_1551243734133_b7d67afd-5ba7-4fd1-b70e-61aa7fc265f3-image.png

    Another post solve this problem by adding the image via code. So I tried it.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QPixmap>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        QPixmap pix (":/Img/Img/Wrench.png");
        ui->labelImageWrench->setPixmap(pix);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    While this method is able to display the wrench image at runtime (see screenshot below)
    0_1551244398950_babaa600-59f2-4ef4-9d96-146f96c7c753-image.png

    It does not display the wrench in Qt Design view (see screenshot below). I need it to be visible here, to get a overall view of how the GUI would look like, to arrange the other components.

    0_1551244514893_40c36d7b-e3f1-49cb-99b3-aadb76c0dfb3-image.png

    Any ideas on how to insert PNG images, preferably in Qt Design, such that it is visible in Qt Design and Runtime?

    This problem is driving me crazy, there seems to be no easy way to insert an image?

    Rgds
    Thug

    J 1 Reply Last reply 27 Feb 2019, 05:36
    0
    • T Thug
      27 Feb 2019, 05:26

      Hi, I'm not a programmer and is new to Qt, checking out if Qt is suitable for GUI design.
      Using free Qt Creator 4.8.1 (based on Qt 5.12.1), on Win 10.

      I can add a PNG image of a wrench, pls see screenshot below.
      0_1551243110051_471ca088-19ab-4951-bbe4-8122137a890d-image.png

      Problem is during Runtime, it is not visible.
      0_1551243242668_91c0ad59-5148-4bbf-b386-10713a245c85-image.png

      I read on other posts to try this "Clean, Run qmake, Run". It didn't work for me.

      I saw another post about adding image file as Resource, so I added Resource.
      0_1551243570561_4de4ab55-a661-4e77-b960-54c6de652fbc-image.png

      Then I try to add the image as a Resource, using "Choose Resource" option (see screenshot below). When I clicked on "Choose Resource", the program freezes, all buttons becomes non interactive. I have to press ESC for the program to "snap out of it." So this is an dead end for me.
      0_1551243734133_b7d67afd-5ba7-4fd1-b70e-61aa7fc265f3-image.png

      Another post solve this problem by adding the image via code. So I tried it.

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QPixmap>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          QPixmap pix (":/Img/Img/Wrench.png");
          ui->labelImageWrench->setPixmap(pix);
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      

      While this method is able to display the wrench image at runtime (see screenshot below)
      0_1551244398950_babaa600-59f2-4ef4-9d96-146f96c7c753-image.png

      It does not display the wrench in Qt Design view (see screenshot below). I need it to be visible here, to get a overall view of how the GUI would look like, to arrange the other components.

      0_1551244514893_40c36d7b-e3f1-49cb-99b3-aadb76c0dfb3-image.png

      Any ideas on how to insert PNG images, preferably in Qt Design, such that it is visible in Qt Design and Runtime?

      This problem is driving me crazy, there seems to be no easy way to insert an image?

      Rgds
      Thug

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 27 Feb 2019, 05:36 last edited by
      #2

      @Thug On what platform are you? What is QtCreator version? For me "Choose Resource..." works as expected (Windows 7, QtCreator 4.7.0).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Thug
        wrote on 27 Feb 2019, 06:20 last edited by
        #3

        Hi jsulm,

        I'm using free Qt Creator 4.8.1, based on Qt 5.12.1, Win 10 Pro.

        My project is a "Qt Widget App" pls see screen below for the option I selected when creating the program.
        0_1551248025185_d1dd1652-33c5-4ae4-b800-fe0228267f5c-image.png

        0_1551248063061_c6b7d121-5c18-4350-8cfd-5d9363ba9b63-image.png

        0_1551248192989_e8ab5ccc-ee35-47c1-b8ca-fbfcf9a686b7-image.png

        J 1 Reply Last reply 27 Feb 2019, 06:46
        0
        • T Thug
          27 Feb 2019, 06:20

          Hi jsulm,

          I'm using free Qt Creator 4.8.1, based on Qt 5.12.1, Win 10 Pro.

          My project is a "Qt Widget App" pls see screen below for the option I selected when creating the program.
          0_1551248025185_d1dd1652-33c5-4ae4-b800-fe0228267f5c-image.png

          0_1551248063061_c6b7d121-5c18-4350-8cfd-5d9363ba9b63-image.png

          0_1551248192989_e8ab5ccc-ee35-47c1-b8ca-fbfcf9a686b7-image.png

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 27 Feb 2019, 06:46 last edited by
          #4

          @Thug Did you check QtCreator bug tracker to see whether this is a known issue? Did you try to disable antivirus software?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 27 Feb 2019, 21:22 last edited by
            #5

            Hi,

            Might be a silly question but are you sure your .qrc file is compiled ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            T 1 Reply Last reply 1 Mar 2019, 10:10
            0
            • S SGaist
              27 Feb 2019, 21:22

              Hi,

              Might be a silly question but are you sure your .qrc file is compiled ?

              T Offline
              T Offline
              Thug
              wrote on 1 Mar 2019, 10:10 last edited by
              #6

              Hi @jsulm , I tried disabling McAfee, the "Add Resource" option still freezes. The bug tracker does not seem to show this bug.

              @SGaist , are you refering to "Clean project, Run Qmake, Run project" in QT Creator? If yes, I have already tried it. Or do you mean compile qrc via command prompt? How do I select "Add Resource" in command prompt?

              I remember the "Add Resource" working, not freezing up 4 days ago when I first installed QT. I did not install anything new nor did any settings since then.

              M 1 Reply Last reply 1 Mar 2019, 12:50
              0
              • T Thug
                1 Mar 2019, 10:10

                Hi @jsulm , I tried disabling McAfee, the "Add Resource" option still freezes. The bug tracker does not seem to show this bug.

                @SGaist , are you refering to "Clean project, Run Qmake, Run project" in QT Creator? If yes, I have already tried it. Or do you mean compile qrc via command prompt? How do I select "Add Resource" in command prompt?

                I remember the "Add Resource" working, not freezing up 4 days ago when I first installed QT. I did not install anything new nor did any settings since then.

                M Offline
                M Offline
                mranger90
                wrote on 1 Mar 2019, 12:50 last edited by
                #7

                @Thug
                You can just edit the .pro file and add the line
                RESOURCES += file.qrc
                where "file" is the name of your resource file.
                As always, when changing the .pro file, make sure that you do a clean/qmake/build cycle.

                T 1 Reply Last reply 4 Mar 2019, 01:14
                1
                • M mranger90
                  1 Mar 2019, 12:50

                  @Thug
                  You can just edit the .pro file and add the line
                  RESOURCES += file.qrc
                  where "file" is the name of your resource file.
                  As always, when changing the .pro file, make sure that you do a clean/qmake/build cycle.

                  T Offline
                  T Offline
                  Thug
                  wrote on 4 Mar 2019, 01:14 last edited by
                  #8

                  Hi, @mranger90 the .pro file already included the .qrc line (pls see screenshot below).

                  0_1551661595201_1c2184da-c5f6-4682-a5a9-e7a52fb9b547-image.png

                  A copy of the zipped project file is at:
                  SG_GUI6

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mranger90
                    wrote on 4 Mar 2019, 14:53 last edited by
                    #9

                    I ran that project on an Ubuntu 18.04 system using Qt 5.12.0
                    With no modifications, the application built and ran but the wrench was not visible.
                    In designer mode, the path to the wrench was to my disk - i.e. /home/joem/SG_GU16/Img/Wrench.png.
                    I changed it to point to the resource entry ":/Res/Img/Wrench.png" in the QLabel/pixmap tab for label_2.
                    Clean/qmake/rebuild/run and the wrench appears.

                    T 1 Reply Last reply 5 Mar 2019, 04:20
                    0
                    • M mranger90
                      4 Mar 2019, 14:53

                      I ran that project on an Ubuntu 18.04 system using Qt 5.12.0
                      With no modifications, the application built and ran but the wrench was not visible.
                      In designer mode, the path to the wrench was to my disk - i.e. /home/joem/SG_GU16/Img/Wrench.png.
                      I changed it to point to the resource entry ":/Res/Img/Wrench.png" in the QLabel/pixmap tab for label_2.
                      Clean/qmake/rebuild/run and the wrench appears.

                      T Offline
                      T Offline
                      Thug
                      wrote on 5 Mar 2019, 04:20 last edited by
                      #10

                      @mranger90 , may I ask how do you change the path in Designer mode?

                      I only see the path
                      "C:\Users\HG\Doucments\Qt\SG_GUI16\Img\Wrench.png"
                      when I mouseover the "wrench.png" in the pixmap tab.
                      0_1551759276431_604a1b71-5633-493e-8257-230a0259c335-image.png

                      Did you select "Choose Resource" or "Choose file"?
                      I selected "Choose file". When I select "Choose Resource" the program freezes like it is looking for something, I need to press ESC to unfreeze it.
                      0_1551759389992_91903a11-5c47-4b3a-b775-4bf517329d7d-image.png

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mranger90
                        wrote on 5 Mar 2019, 12:52 last edited by
                        #11

                        There are a couple of ways.
                        the "..." button should give you the option.
                        or the DownArrow will allow you to choose a resource.
                        Since the png is already in the resource file, this should work.

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 6 Mar 2019, 20:36 last edited by
                          #12

                          Hi
                          Its not the project it self as it seems to work with same compiler and Qt version.
                          alt text

                          Have not heard it freezing before when trying to open the resource browse window.
                          very odd.

                          T 1 Reply Last reply 8 Mar 2019, 09:23
                          0
                          • G Offline
                            G Offline
                            Gerhard
                            wrote on 6 Mar 2019, 20:57 last edited by
                            #13

                            Run qmake after adding Image to Resource file

                            Gerhard

                            1 Reply Last reply
                            0
                            • M mrjj
                              6 Mar 2019, 20:36

                              Hi
                              Its not the project it self as it seems to work with same compiler and Qt version.
                              alt text

                              Have not heard it freezing before when trying to open the resource browse window.
                              very odd.

                              T Offline
                              T Offline
                              Thug
                              wrote on 8 Mar 2019, 09:23 last edited by
                              #14

                              @mrjj oic, then it might be my computer's settings or background programs.

                              1 Reply Last reply
                              0

                              4/14

                              27 Feb 2019, 06:46

                              10 unread
                              • Login

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