2017-01-04 2 views

답변

1

의 너비를 더 높은 값 (contentItem의 너비)으로 설정하지 않은 이유는 하나만 상상할 수 있습니다. '당신에게

Item { 
    id: limitedWidthItemToAnchorTo 
    width: 200 // the width the ScrollView was supposed to have 
    height: 400 

    ScrollView { 
     width: contentItem.width + __verticalScrollBar.width// Don't limit the width. 
     height: 400 // Limit only the height. 
     horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff // You don't need them. 
     contentItem: Rectangle { 
      width: 700 // This will set the ScrollViews width. 
      height: 600 // The height will be clipped by the ScrollView. 
         // You can scroll though. 

      gradient: Gradient { 
       GradientStop { position: 0; color: 'red' } 
       GradientStop { position: 1; color: 'blue' } 
      } 
      border.width: 10 
     } 
    } 
} 

당신은이 때문에, Item에 닻을 싸서 것이고, :

ScrollView를 제약은 폭이 있어요, 당신은 간단한 트릭을 사용하지 않으면 서, 그렇게 할 수 있으려면 좋을거야. 마스크를 사용할 수도 있지만 이것은 더 복잡 할 것입니다.

그 자체로 Item의 경계 상자를 사용하여 클리핑이 수행되므로 수평 또는 수직으로 만 클립 할 수 없습니다.

+0

감사합니다.하지만 'ScrollView'에 대한 질문이었습니다. 이것도 적용됩니까? –

+0

물론. 'ScrollView'는'ListView'뿐만 아니라'Item'도 상속받습니다. 내 대답을 업데이트합니다. 제대로 읽지 않으려면 부탁하십시오. – derM

+0

그래, 그 일했다! 고맙습니다. –

0

원하는 방향으로 만 스크롤하려는 경우에는 속성 바인딩을 사용하여 콘텐츠 항목의 너비/높이를 ScrollView의 너비/높이로 설정하면됩니다 (ScrollView 내부의 항목은 ScrollView.contentItem). 아래 예제는 수직으로 만 스크롤합니다. 실제로 작동하는지 확인해야하는 경우 테스트를 거쳤습니다.

Item { 
    ScrollView { 
     id: scrollview1 
     anchors.fill: parent 
     anchors.margins: 20 
     clip: true 

     ColumnLayout { 
      width: scrollview1.width 
     } 
    } 
} 
관련 문제