2015-02-03 4 views
0
이 코드가

의 왼쪽 상단에 오버레이 버튼 (최소로 감소)QML QT (5) : 리사이즈 된 화상

Example in qmlscene

: 다음과 같은 화상을 생성

import QtQuick 2.0 
import QtQuick.Controls 1.3 

Item { 
    Image { 
     id: img 
     source: "cluster.png" 
     width: 150 
     height: 150 
     fillMode: Image.PreserveAspectFit 
    } 

    Button { 
     id: butn 
     anchors.left: img.left 
     anchors.top: img.top 
     width: 20 
     height: 20 
     text: "Push!" 
    } 
} 

그러나 의 왼쪽 상단에 단추를 넣고 싶습니다. 이미지를 클릭하십시오.

에서

전체 이미지 : http://susepaste.org/34762236

는 QML로이 가능합니까?

+0

cluster.png을 업로드 할 수 있습니까? 지금은 다소 혼란 스럽습니다. – Mitch

+1

@Mitch 좋은 생각, 크기를 조정 (원본은 5000x5000 정도)하고 업로드합니다. – Einar

답변

2

paintedHeight propertypaintedWidth이 있도록 크기 조정 된 이미지의 실제 크기에 액세스해야합니다.

이 당신은 양자 택일 앵커 마진 대신 x 또는 y을 사용할 수 있습니다

Item { 
    Image { 
     id: img 
     source: "cluster.png" 
     width: 150 
     height: 150 
     fillMode: Image.PreserveAspectFit 
    } 

    Button { 
     id: butn 
     anchors.left: img.left 
     anchors.top: img.top 
     anchors.leftMargin: (img.width - img.paintedWidth)/2 
     anchors.topMargin: (img.height - img.paintedHeight)/2 
     width: 20 
     height: 20 
     text: "Push!" 
    } 
} 

될 것입니다.