file:///home/biergaizi/WeCase.commit/src//ui/SmileyDelegate.qml:6:5:
QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn
anchors for items inside Column
Run Code Online (Sandbox Code Playgroud)
为什么我明白了?我试图注释每一行而没有找到答案。我对此一无所知。
SmileyView.qml
import QtQuick 1.0
Rectangle {
width: 300; height: 200
GridView {
id: grid
anchors.fill: parent
cellWidth: 36; cellHeight: 40
model: SmileyModel
delegate: SmileyDelegate {}
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
focus: true
}
}
Run Code Online (Sandbox Code Playgroud)
SmileyDelegate.qml
import QtQuick 1.0
Item {
width: grid.cellWidth; height: grid.cellHeight
Column {
anchors.fill: parent
Image { source: path; anchors.horizontalCenter: parent.horizontalCenter }
Text { text: name; anchors.horizontalCenter: parent.horizontalCenter }
MouseArea {
anchors.fill: parent
onClicked: {
highlight: color: "lightsteelblue"; radius: 5
grid.currentIndex = index
}
onDoubleClicked: {
parentWindow.returnSmileyName('[' + name + ']')
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
列尝试将您的MouseArea锚定到“图像”和“文本”旁边,但是MouseArea指定其锚定以填充其父级。这两件事是矛盾的,因此为什么会出现错误。
如果将MouseArea移出Column并移入SmileyDelegate的基本Item,则可能会按预期工作。