我使用QML的内置DropShadow类型(导入QtGraphicalEffects)生成包含在项中的一些矩形的阴影。DropShadow也是所述Item的一个子类。但有时阴影渲染得很糟糕。我动态地创建屏幕并将其添加到SwipeView中;代码如下:
swipeView.addItem(tasksScreen.createObject(swipeView))
swipeView.incrementCurrentIndex()"tasksScreen“是矩形和DropShadow所在的屏幕。下面的视频描述了问题和生成此行为的代码:
发布于 2020-05-20 13:29:24
问题在于代码中的源代码属性,您已经将源代码设置为代码中的父项。将源作为可视对象(矩形)。我已附上密码供你参考。
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Component {
id: swipeviewComponentId
Item {
id: itemId
Rectangle {
id: rectangleId
anchors.fill: parent
anchors.margins: 10
radius: 10
}
DropShadow {
anchors.fill: source
horizontalOffset: 3
verticalOffset: 3
radius: 8.0
samples: 17
color: "#80000000"
source: rectangleId
}
}
}
Column {
anchors.fill: parent
anchors.margins: 10
spacing: 10
SwipeView {
id: swipeViewId
width: parent.width
height: parent.height - addButtonId.height - (2 * parent.spacing) - pageIndicatorId.height
}
PageIndicator {
id: pageIndicatorId
currentIndex: swipeViewId.currentIndex
count: swipeViewId.count
anchors.horizontalCenter: parent.horizontalCenter
}
Button {
id: addButtonId
width: parent.width
height: 40
text: "Add item"
onClicked: {
swipeViewId.addItem(swipeviewComponentId.createObject(swipeViewId,
{height: swipeViewId.height, width: swipeViewId.width}))
swipeViewId.incrementCurrentIndex()
}
}
}
}https://stackoverflow.com/questions/61913040
复制相似问题