2011-08-16 5 views
7

QML을 처음 사용합니다. 제가 알고 있듯이, 모든 요소에는 크기를 결정하는 폭과 높이가 있습니다. 사용자가 화면 해상도를 변경하면 최종 출력이 이상하게 보입니다. 화면 해상도에 따라 요소의 크기를 동적으로 제어 할 수있는 방법이 있습니까?QML의 요소 크기

답변

8

고정 값을 사용하는 대신 루트 요소 크기에 비례하여 요소의 크기를 결정하는 요인에 따라 루트 요소의 height 및 을 곱할 수 있습니다. 또한 QML anchors을 사용할 수 있습니다. 이것으로 완전히 확장 가능한 GUI를 만들 수 있습니다

import QtQuick 1.0 

Item { 
    id: root 

    // default size, but scalable by user 
    height: 300; width: 400 

    Rectangle { 
     id: leftPanel 

     anchors { 
      top: parent.top 
      left: parent.left 
      bottom: parent.bottom 
     } 
     width: root.width * 0.3 
     color: "blue" 
    } 

    Rectangle { 
     id: topPanel 

     anchors { 
      top: parent.top 
      left: leftPanel.right 
      right: parent.right 
     } 
     height: root.height * 0.2 
     color: "green" 
    } 


    Rectangle { 
     id: contentArea 

     anchors { 
      top: topPanel.bottom 
      left: leftPanel.right 
      right: parent.right 
      bottom: root.bottom 
     } 
     color: "white" 

     Text { 
      text: "Hi, I'm scalable!" 
      anchors.centerIn: parent 
      font.pixelSize: root.width * 0.05 
     } 
    } 
} 

내가 모든 환경에서 사용할 수 있습니다 순수 QML과 화면 해상도를 얻을 수있는 방법을 잘 모릅니다.

모바일 장치에서 화면 해상도를 결정하려면 QML Screen Element을 사용할 수 있습니다.

데스크톱 응용 프로그램에서 C++로 화면 해상도를 얻을 수 있으며 (예 : QDesktopWidget) available in QML이됩니다.

+0

완벽한, 감사합니다. 나는 이것을 시도 할 것이다. – Groovy

+1

[QML 화면 요소] (http://qt-project.org/doc/qt-5/qml-qtquick-window-screen.html)는 QML 5에서도 사용할 수 있습니다. – rmoestl

관련 문제