2

特定のテキストと固定幅のフォントサイズをカスケードで取得する方法はありますか?

私は試していました:

TextField{
  autoFit: TextAutoFit.FitToBounds
}

ただし、テキストは常に左揃えで表示されます。要件は、テキストを中央揃えにして、可変フォント サイズのラベルを固定四角形にレンダリングすることです。

4

2 に答える 2

0

現時点では、BB10 Cascades にはフォント メトリックがないため、フォントがラベルに収まらないかどうかを確認してサイズを変更することはできません。

layoutUpdateHandler で一種のハックを使用して、大まかなサイズ変更を行うことができますが、お勧めしません。テキストが頻繁に変更されるとちらつきが見られますが、一度しか設定されていない場合は問題ない場合があります。「onCreationCompleted」に設定されたテキストを変更して、テキストのサイズが自動的に変更されるかどうかを確認します。

    Container {
        id: root
        implicitLayoutAnimationsEnabled: false 

        background: Color.Cyan
        property int width: 500
        property string  text: ""
        property double textSize: 20
        layout: DockLayout {
        }
        attachedObjects: [
            LayoutUpdateHandler {
                onLayoutFrameChanged: {
                    if (layoutFrame.width > root.width) {
                        root.textSize = root.textSize - 1
                    }
                }
            }
        ]
        Label {
            implicitLayoutAnimationsEnabled: false 
            maxWidth: root.width
            text: root.text
            textStyle {
                fontSize: FontSize.PointValue
                fontSizeValue: root.textSize
            }
        }
        Label {
            implicitLayoutAnimationsEnabled: false 
            text: root.text
            opacity: 0
            textStyle {
                fontSize: FontSize.PointValue
                fontSizeValue: root.textSize
            }

        }
        onCreationCompleted: {
            root.text = "Hello World AAAAAAAA"
        }
    }
于 2013-07-23T14:36:20.400 に答える