2014-10-18 2 views
0

말하면 FlickableImage이있는 것 같습니다. 그에 따라 contentWidthcontentHeight을 업데이트해야합니다. 수동으로 적절한 계산을하는 것이 가능하지만, Image (그리고 다른 Item)의 경계 사각형을 얻는 방법이 있는지 궁금합니다. (Mitch's suggestion에 응답)회전 된 항목의 경계 사각형을 알아 보는 방법

EDIT :

언뜻 그것은 굉장한 예처럼 보였다. 나는 심지어 내가 뭔가를 놓치고 있다고 생각하기 시작했다. Item.childrenRect 속성 그룹 ... 불행히도, 경계가 자식 아이템 주위에 그려 지도록 제공된 예제를 수정하면, 나는 자신이 다시 childrenRect의 속성 항목 회전을 존중하지 마십시오.

import QtQuick 2.3 
import QtQuick.Controls 1.2 

Item { 
    width: 400 
    height: 400 

    Component.onCompleted: addChildItem() 

    function addChildItem() { 
     var rect = Qt.createQmlObject("import QtQuick 2.3; Rectangle {}", container); 
     rect.x = Math.random() * 200; 
     rect.y = Math.random() * 200; 
     rect.width = 64 * slider.value; 
     rect.height = 64 * slider.value; 
     rect.color = "green"; 
     rect.opacity = 0.5; 
     rect.rotation = Math.random() * 360; 
    } 

    Row { 
     anchors.horizontalCenter: parent.horizontalCenter 
     anchors.bottom: parent.bottom 

     Slider { 
      id: slider 
      value: 0.5 

      Text { 
       text: "Child item size" 
       anchors.horizontalCenter: parent.horizontalCenter 
       anchors.bottom: parent.top 
      } 
     } 

     Button { 
      text: "Add child item" 
      onClicked: addChildItem() 
     } 
    } 

    Item { 
     id: container 
     x: 50 
     y: 50 
    } 

    Item { 
     x: container.x 
     y: container.y 
     Rectangle { 
      x: container.childrenRect.x 
      y: container.childrenRect.y 
      width: container.childrenRect.width 
      height: container.childrenRect.height 
      color: "transparent" 
      border.color: "black" 
     } 
    } 
} 

답변

0

childrenRect 당신에게 고려 회전 경계 RECT를 제공해야하지만, 버그가있다 : 아래를 참조 childrenRect doesn't take transformations into account.


원래 답 :

사용 childrenRect :

import QtQuick 2.3 
import QtQuick.Controls 1.2 

Item { 
    width: 400 
    height: 400 

    Component.onCompleted: addChildItem() 

    function addChildItem() { 
     var rect = Qt.createQmlObject("import QtQuick 2.3; Rectangle {}", container); 
     rect.x = Math.random() * 100; 
     rect.y = Math.random() * 100; 
     rect.width = 64 * slider.value; 
     rect.height = 64 * slider.value; 
     rect.color = "green"; 
     rect.opacity = 0.5; 
     rect.rotation = Math.random() * 360; 
    } 

    Row { 
     anchors.horizontalCenter: parent.horizontalCenter 
     anchors.bottom: parent.bottom 

     Slider { 
      id: slider 
      value: 0.5 

      Text { 
       text: "Child item size" 
       anchors.horizontalCenter: parent.horizontalCenter 
       anchors.bottom: parent.top 
      } 
     } 

     Button { 
      text: "Add child item" 
      onClicked: addChildItem() 
     } 
    } 

    Item { 
     id: container 
     anchors.centerIn: parent 
    } 

    Text { 
     text: "Total rotated bounds" 

     Rectangle { 
      id: boundsRect 
      width: container.childrenRect.width 
      height: container.childrenRect.height 
      anchors.top: parent.bottom 
      color: "transparent" 
      border.color: "black" 
     } 
    } 
} 

example screenshot

+0

불행히도, 이것이 내가 원하는 것만은 아닙니다. 내 초기 게시물의 편집을 참조하십시오. –

+0

맞아 ... 나는 지금 이것을 모호하게 기억한다; 애들이있는 버그가 있어요. 레트. 내 대답을 업데이트했습니다. – Mitch

+0

는 (는) 버그 리포트에 투표함. 그것이 부숴지기를 기다리고있을 것입니다. 이 질문 및 답변 쌍이 향후 적절하게 될 수 있도록 귀하의 답변을 미리 수락합니다. –

관련 문제