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. Adding an image in Qt Designer?
Forum Updated to NodeBB v4.3 + New Features

Adding an image in Qt Designer?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 7 Posters 68.5k 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.
  • S Offline
    S Offline
    sierdzio
    Moderators
    wrote on 20 May 2013, 14:11 last edited by
    #2

    No, "setIcon":http://qt-project.org/doc/qt-4.8/qabstractbutton.html#icon-prop() requires only a valid QIcon object. The source file can be any file on your local drive or inside QRC resource.

    (Z(:^

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hardcodes.de
      wrote on 20 May 2013, 14:17 last edited by
      #3

      You can

      create a new resource file

      add the jpeg to the resource file

      run qmake

      add the resource as icon to your button

      while(!sleep){++sheep;}

      1 Reply Last reply
      1
      • S Offline
        S Offline
        swilliams2
        wrote on 20 May 2013, 14:26 last edited by
        #4

        but when I create a "push button" by dragging one across and right click it then click "Change StyleSheet..." I get a box up, and from that box it looks like I can add images, but I can only add qrc files, so how do I get a qrc file with images in it? =]

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hardcodes.de
          wrote on 20 May 2013, 15:22 last edited by
          #5

          To get the resource file:

          create a new resource file in your project

          add the image file, then

          run qmake (or the images will not show up in the UI designer)

          In the UI designer

          • select an icon for your button, you should get a dialog where you can choose the image that should be on that button.

          while(!sleep){++sheep;}

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vezprog
            wrote on 20 May 2013, 15:32 last edited by
            #6

            You must look at the properties on the bottom right hand side of the QtCreator window for the selected QObject. There is a setting to set the icon by clicking the "..." button, as well as changing the icon dimensions on the button towards the bottom of the settings.

            QToolButton as a little more flexibility with icon / text positioning but is mostly used in a toolbar.

            You can also set the icon on the button programmatically if you want to by referencing the image in a resource file or on the local system if you plan on shipping it with the application.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on 20 May 2013, 16:05 last edited by
              #7

              You can also use non-resource images in stylesheets. There's just no button for it in the designer so you need to type it manually, eg.
              @
              background-image: url(whatever\image.jpg)
              @
              but this is discouraged, because you need to be careful not to use absolute paths (will break deployment) and there are more files to move around. Resources are packed into the executable so there're few less problems to remember later.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                swilliams2
                wrote on 21 May 2013, 09:03 last edited by
                #8

                I was just using Designer, I didn't even open up Creator, I feel abit stupid now :L
                Thanks everyone =]

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  Fatal
                  wrote on 12 May 2014, 15:32 last edited by
                  #9

                  How do I run Qmake?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andreyc
                    wrote on 12 May 2014, 15:43 last edited by
                    #10

                    From command line depends on your OS. Form example in Linux
                    @
                    $HOME/Qt5.2.1/5.2.1/gcc_64/bin/qmake
                    @

                    From QtCreator

                    • Right click on a project and select "Run qmake"
                    • Menu "Build" then "Run qmake"
                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sierdzio
                      Moderators
                      wrote on 12 May 2014, 15:43 last edited by
                      #11

                      [quote author="Fatal" date="1399908737"]How do I run Qmake?[/quote]

                      If you use Qt Creator, it will do it automatically. If not, you can run it from the console (qmake is either in your PATh or in <qt dir>/qtbase/bin).

                      (Z(:^

                      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