2015-06-24 48 views
1

我想實現的圖像瀏覽器(排序):使用C++和QMLQT5 QML ListView的內容放大

  • 模型/視圖的方法
  • 的照片僅僅是ListView填補與Image(委託)項

這裏是一段代碼:

property double zoomFactor: 1.5; 
property double imgScale: 1; 

CustomToolBar 
{ 
    id: toolBar 
    onZoomInSignal: 
    { 
     imgScale = imgScale*zoomFactor; 
    } 
    onZoomOutSignal: 
    { 
     imgScale = imgScale/zoomFactor; 

    } 
    onZoomFitSignal: 
    { 
     imgScale = 1; 
    } 
} 

Rectangle 
{ 
    id: bgRect 

    Layout.fillWidth: true 
    Layout.fillHeight: true 

    color: "Grey" 

    anchors.margins: 10 

    ScrollView 
    { 
     id: scrollView 
     anchors.fill: parent 

     ListView 
     { 
      id: listView 

      anchors.fill: parent 
      clip: true 

      spacing: 10 

      model: listItemModel 

      anchors.top: parent.top 
      anchors.bottom: parent.bottom 
      anchors.left: parent.left 
      anchors.right: parent.right 

      anchors.margins: 10 

      boundsBehavior: Flickable.StopAtBounds 

      delegate: Image 
      { 
       id: item_id 

       anchors.horizontalCenter: parent.horizontalCenter 
       source: item_img_path + "/" + Math.random() 

       scale: imgScale 
      } 
     } 
    } 
} 

圖像加載正確,我需要能夠縮放它們。

爲了放大,我只是修改Image委託人的scale財產。

  • 圖像不進行縮放(scale = 1)正確:

No zoom (scale = 1)

  • 圖像未縮放(scale = 1/1.5)錯了! (?)間距的圖像正在增加:

Zoom minus (scale = 1/1.5)

  • 圖像縮放(scale = 1.5)錯了!圖像重疊:

Zoom plus (scale = 1.5)

正如你所看到的,變焦減去增量間距(我非常不知道它是真正的間距)的圖像之間,並且變焦加上重疊圖片。

此外,在放大時爲ScrollView設置水平滾動條會很好,但我無法做到這一點。

任何人都可以幫助我嗎?

感謝


編輯:

grillvott圖像提出了solution被放大/縮小正確,但整個ListView正變得越來越小/大與他們:

enter image description here

結果應該是這樣的東西( GIMP模式ON):

enter image description here

任何想法?

+0

幫助我理解你,圖像應該是什麼樣子,在輸入/輸出的情況下縮放?就像尺寸1一樣大小? – Cits

+0

好吧,它們應該更小/更大,正如你可以在屏幕截圖中看到的那樣,但它們應該保持互相之間的一致性,因爲它們的scale = 1。 – Giancarlo

回答

2

我不認爲scale會考慮任何界限。你可以封裝的圖像,並使用fillMode,以確保圖像相應縮放:

delegate: Item { 
    anchors.horizontalCenter: parent.horizontalCenter 
    width: img.sourceSize.width * imgScale 
    height: img.sourceSize.height * imgScale 
    Image { 
     id: img 
     anchors.fill: parent 
     source: item_img_path + "/" + Math.random() 
     fillMode: Image.Stretch 
    } 
} 
+0

哦謝謝man..this工作,圖像正確放大/縮小,但整個ListView越來越小/更大: – Giancarlo

+1

@Giancarlo你想要什麼?你說你不希望圖像重疊或間距變大,你不能擁有這些圖像,除非你裁剪圖像,否則你會得到更多的間距,如果圖像變得更小。 – GrecKo

+0

好吧,我希望最後的截圖是真實的,如果可能的話); – Giancarlo