首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将[未定义的]分配给QColor

无法将[未定义的]分配给QColor
EN

Stack Overflow用户
提问于 2018-07-05 08:36:26
回答 1查看 2.9K关注 0票数 3

我正在构建/运行一个QT5.11代码。代码中有一个QML样式,如下所示:

代码语言:javascript
复制
// Button style delegate
    Component {
        id: enabledButtonStyle
        ButtonStyle {
            padding.top: 0
            padding.bottom: 0
            padding.right: 0
            padding.left: 0
            background: Rectangle {
                implicitHeight: enableButton.height
                implicitWidth: enableButton.width
                color: {
                    if ((buttonEnabled || hoverAlways) && enabled) {
                        if (propertyButton.hovered)
                            hoveredBgColor
                        else
                            defaultBgColor
                    } else {
                        selectedBgColor
                    }
                    if (propertyButton.pressed)
                        selectedBgColor
                }
            }
        }
    }

但是,我在color: {行收到了以下警告

代码语言:javascript
复制
Unable to assign [undefined] to QColor

我想不出如何解决这个错误。有人能给点提示吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-05 08:47:30

你必须使用return

代码语言:javascript
复制
color: {
    if ((buttonEnabled || hoverAlways) && enabled) {
        if (propertyButton.hovered)
            return hoveredBgColor
        else
            return defaultBgColor
    } else {
        return selectedBgColor
    }
    // will never enter this line since the if else is absolute.
    /*if (propertyButton.pressed)
        return selectedBgColor*/ 
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51186780

复制
相关文章

相似问题

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