2017-06-03 39 views
0

我在我的qml代码中使用GridView,但它只显示一行中的所有项目,但我不想要它。您可以在下面的图片中看到: click to see picture ,这是我的代码:为什么GridView项目不包装?

import QtQuick 2.8 
import QtQuick.Controls 2.1 
import Qt.labs.folderlistmodel 2.1 

ApplicationWindow{ 
    id: a 
    width: 480 
    height: 640 
    FolderListModel{ 
     id : listModel 
     folder: "/home/muhammad/Pictures" 
     nameFilters: ["*.jpg"] 
    } 
    Component{ 
     id: dd 
     Image { 
      id: m 
      width: a.width/3 
      height: width 
      source: filePath 
     } 
    } 

    GridView{ 
     verticalLayoutDirection: GridView.TopToBottom 
     layoutDirection: Qt.LeftToRight 
     anchors.fill: parent 
     flow: GridView.FlowLeftToRight 
     model: listModel 
     delegate: dd 
    } 

} 

我该怎么解决呢?

回答

1

GridView中每个单元格的大小由cellWidthcellHeight决定。默认的单元格大小为100x100。请注意,单元格大小决定了视图的布局。代表们可以决定如何覆盖为每个单元格保留的区域。例如,您可能需要将Image -delegate调整为cellWidthcellHeight,并将其fillMode设置为Image.PreserveAspectFit

GridView { 
    id: gridView 

    cellWidth: 200 
    cellHeight: 200 

    delegate: Image { 
     width: gridView.cellWidth 
     height: gridView.cellHeight 
     fillMode: Image.PreserveAspectFit 
    } 
} 
+0

在此先感谢!有用! ;) –

相关问题