首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QML DropShadow有时呈现得很糟糕

QML DropShadow有时呈现得很糟糕
EN

Stack Overflow用户
提问于 2020-05-20 12:22:24
回答 1查看 516关注 0票数 0

我使用QML的内置DropShadow类型(导入QtGraphicalEffects)生成包含在中的一些矩形的阴影。DropShadow也是所述Item的一个子类。但有时阴影渲染得很糟糕。我动态地创建屏幕并将其添加到SwipeView中;代码如下:

代码语言:javascript
复制
swipeView.addItem(tasksScreen.createObject(swipeView))
swipeView.incrementCurrentIndex()

"tasksScreen“是矩形和DropShadow所在的屏幕。下面的视频描述了问题和生成此行为的代码:

https://yadi.sk/i/mwl_8IZmm_jetQ

EN

回答 1

Stack Overflow用户

发布于 2020-05-20 13:29:24

问题在于代码中的源代码属性,您已经将源代码设置为代码中的父项。将源作为可视对象(矩形)。我已附上密码供你参考。

代码语言:javascript
复制
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()
            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61913040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档