我关注@include rwd( upto-desktop, $upto-desktop ) { }
:
QML Item
现在,当我点击import QtQuick 2.5
import QtQuick.Layouts 1.2
Item
{
clip: true
id: ueItemCategorySelector
signal ueSignalStartProductSelectorAnimation()
ListModel
{
id: ueCategoriesModel
ListElement {}
ListElement {}
ListElement {}
ListElement {}
function ueGetChildCategories () {}
}
Rectangle
{
id: ueCategorySelectorWrapper
radius: 16
gradient: Gradient
{
GradientStop
{
position: 0
color: "#ffffff"
} // GradientStop
GradientStop
{
position: 1
color: "#000000"
} // GradientStop
} // Gradient
border.color: "#4682b4"
border.width: 1
antialiasing: true
anchors.fill: parent
ColumnLayout
{
anchors.margins: parent.radius/2
spacing: 0
antialiasing: true
anchors.fill: parent
ListView
{
id: ueCategoryListView
antialiasing: true
orientation: ListView.Horizontal
clip: true
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignVCenter
Layout.margins: 8
spacing: 8
highlightFollowsCurrentItem: true
Component.onCompleted:
{
model=ueCategoriesModel
//TODO once component is loaded, the first category must be selected (programmatically) to show products
} // Component.onCompleted
delegate: Rectangle
{
id: ueCategorySelectorDelegate
radius: 16
width: 256
height: ueCategoryListView.height-2*Layout.margins
clip: true
border.color: "#4682b4"
antialiasing: true
gradient: Gradient
{
GradientStop
{
position: 0
color: "#000000"
ParallelAnimation on color
{
id: ueCategorySelectorColorAnimation
loops: 1
running: false
ColorAnimation
{
from: "#4682b4"
to: "#000000"
duration: 100
} // ColorAnimation
} // ParallelAnimation
} // GradientStop
GradientStop
{
position: 1
color: "#ffffff"
} // GradientStop
} // Gradient
MouseArea
{
//id: ueCategorySelectorDelegateMouseArea
anchors.fill: parent
onClicked:
{
if(index!==ueCategoryListView.currentIndex)
{
ueCategoriesModel.ueGetChildCategories(ueCategoriesModel.get(index).ueRoleId);
ueCategorySelectorColorAnimation.running=true;
ueItemCategorySelector.ueSignalStartProductSelectorAnimation();
} // if
ListView.currentIndex=ListView.index;
} // onClicked
} // MouseArea
ColumnLayout
{
anchors.fill: parent
antialiasing: true
spacing: 8
Image
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignTop
Layout.topMargin: ueCategorySelectorWrapper.radius+4
fillMode: Image.PreserveAspectFit
horizontalAlignment: Image.AlignHCenter
verticalAlignment: Image.AlignVCenter
antialiasing: true
source: "image://ueCategoriesModel/"+model.ueRoleImage
} // Image
Text
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter|Qt.AlignBottom
Layout.bottomMargin: ueCategorySelectorWrapper.radius+4
color: "#000000"
text: model.ueRoleName
wrapMode: Text.WordWrap
font.family: "Courier"
textFormat: Text.RichText
font.bold: true
font.pointSize: 10
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
} // Text
} // ColumnLayout
} // delegate
} // ListView
} // ColumnLayot
} // Rectangle
} // Item
时,会弹出以下QML运行时错误:
MouseArea
为什么我无法从qrc:/gui/items/UeCategorySelector.qml:132: ReferenceError: ueItemCategorySelector is not defined
的{{1}}代码块发送/发出信号?
我尝试过来自Can't emit signal in QML custom Item的解决方案,但它对我不起作用。我已将MouseArea
添加到外JavaScript
,我现在正在调用信号
id
我现在什么都不懂。如果我将Item
内的代码(更改语句的顺序)更改为
ueItemCategorySelector.ueSignalStartProductSelectorAnimation();
然后它工作正常。为什么呢?
答案 0 :(得分:0)
我已将onClicked
内的代码更改为:
onClicked:
{
if(index!==ueCategoryListView.currentIndex)
{
ueCategorySelectorColorAnimation.running=true;
ueItemCategorySelector.ueSignalStartProductSelectorAnimation();
ueCategoriesModel.ueGetChildCategories(ueCategoriesModel.get(index).ueRoleId);
} // if
}
现在它有效,但我不知道为什么。