Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Image in Rectangle does not show
Qt 6.12 LTS is out! See what's new in the release blog

Image in Rectangle does not show

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 651 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.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by
    #1

    I tryed annother code from an example. But it does not work.

    Following code:

    import QtQuick 2.14
    
    Rectangle {
        id: root
        width: background.width; height: background.height
    
        Image {
            id: background
            source: "assets/background_medium.png"
        }
    }
    

    When I run this I get a window which appears in the top left corner of my screen with size = 0. I can drag it bigger but nothing shows.

    I don't get the usuall message that the image could not be loaded so It should be ok.

    Why is it not working?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sandro4912
      wrote on last edited by sandro4912
      #2

      @sandro4912 said in Image in Rectangle does not show:

      width: background.width; height: background.height

      It sounds crazy but now It works.

      What I did. I changed the code to this:

      Rectangle {
          id: root
      
          Image {
              id: background
              source: "assets/background_medium.png"
          }
      
          width: background.width; height: background.height
      }
      

      Then run it. And it worked.

      Afterwards I changed this back to the original

      Rectangle {
          id: root
          width: background.width; height: background.height
      
          Image {
              id: background
              source: "assets/background_medium.png"
          }
      }
      

      And now this also works.

      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
      • Unsolved