根据标签值标记颜色

时间:2013-08-30 04:31:47

标签: blackberry blackberry-10

我有一个带有这样标签的容器...... 但如果Label值为负,我需要添加红色,否则为绿色。我怎么能在Qml的BB 10级联中做到这一点。

Container {
    leftPadding: 15.0
    rightPadding: 15.0
    layout: StackLayout {
        orientation: LayoutOrientation.LeftToRight
    }
    topPadding: 20.0

    Label {
        id: symbol
        text: ListItemData.Symbol_En

        // Text Style and size etc
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 4
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }
    Label {
        id: change
        text: ListItemData.PerChange
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 2
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }
    Label {
        id: ltp
        text: ListItemData.LTP
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 1
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }
    Label {
        id: highValue
        text: ListItemData.High
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 1
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }
    Label {
        id: lowValue
        text: ListItemData.Low
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 1
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

    }

1 个答案:

答案 0 :(得分:0)

这样的事情(只是有问题的标签):

Label {
        id: highValue
        text: ListItemData.High
        textStyle.color: ListItemData.High.indexOf("-") < 0 ? Color.Green : Color.Red 
        textStyle.base: SystemDefaults.TextStyles.SubtitleText
        textStyle.fontSizeValue: 30.0
        layoutProperties: StackLayoutProperties {
            spaceQuota: 1
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center
    }