What's wrong with screen size and parent's size on Android



  • Hello, Guys! I can't understand why does a one snippet work properly and other doesn't when they're absolutely similar speaking of logic IMO.

    ApplicationWindow {
        id: root
        title: "My 1st QML App"
        width: 480
        height: 640
        visible: true
         
          Rectangle {
              id: rectangle
              anchors.centerIn: parent
              width: parent.width
              height: parent.height   
              color: "#9B76CC"
          }
    }
    

    Here ApplicationWindow is our parent, so this because width: 480 and height: 640. As result, I'm getting a color-filled, full-screened rectangle on my smartphone's screen. And I'm expecting the same result as if I had set width: 480 and height: 640 without using parent keyword. In both situations, we have the same sizes, but it appears that in the latter case we get small, i.e. not full-screened, rectangle on my nexus5's screen. What's the problem?



  • Your Nexus 5's screen is not 480x640. I don't know anything about Qt on Android, but my guess would be that an ApplicationWindow on Android fills the screen (which is actually 1920x1080) regardless of its width and height settings, thus parent.width is not what you think it is in your Rectangle.



  • Yeah, you're correct. So the bottom line is that ApplicationWindow fills whole screen by default. I think so. Unfortunately, I can't prove it, i.e. desribe whole process with facts and links to documentation, but I tried different ways w/w/o ApplicationWindow and tricks with proportions and your guess was correct. Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.