2017-06-05 13 views
1

QMLとQtQuickを学習する過程で、次の問題が発生しました。テキストを配置する要素を減らすことによって、フォントサイズを自動的に減らすことができます。 は、今私はそれがあまりにもエレガントな作品ではなく、この方法qmlのテキストを自動サイズ変更する

Rectangle { 
id: main_window 
width: 700 
height: 500 

property int main_w: main_window.width 

Rectangle { 
    width: 400 
    height: 400 
    anchors.centerIn: parent 
    color: 'green' 

    Text { 
     text: "SIZE ME!!!" 
     anchors.centerIn: parent 
     color: 'white' 
     font.pointSize: { 
      if (main_window.main_w < main_window.width) 
       return main_window.main_w/35 // we need 20pt 
      return main_window.width/35 
     } 
     visible: { 
      if (parent.width < 100) 
       return false 
      return true 
     } 
    } 
} 

を持っています。たぶんテキストが自動的にサイズ変更されるいくつかの方法があります。 ColumnLayoutのラップが機能しない場合

助けてください。

Rectangle { 
id: root 
width: 700 
height: 700 
property int mrg: 10 

Rectangle { 
    anchors.centerIn: parent 
    width: 400 
    height: 400 
    color: 'green' 

    Text { 
     id: field 
     text: "Size me!" 
     minimumPointSize: 10 
     font.pointSize: 60 
     fontSizeMode: Text.Fit 
     color: 'white' 
     anchors.centerIn: parent 
    } 
} 
} 

答えて

3

は(Text.HorizontalFitText.VerticalFitまたはText.Fit)を自動サイズ設定するテキスト要素fontSizeModeプロパティを使用しますしようとしてここにfontSizeModeと私のコードをあなた

をありがとうございます。 minimumPixelSizeプロパティで最小フォントサイズを調整できます。

詳細

+0

ためhttp://doc.qt.io/qt-5/qml-qtquick-text.html#fontSizeMode-propを参照してください。私は、これらのメソッドを見て、いくつかの理由で、何の効果 –

+0

@v_sith_vありません:あなたは 'fontSizeMode'-プロパティであなたの試みを含めるために、あなたの質問を編集もらえますか? – derM

+0

私はこの問題を理解しました。あなたのアドバイスは正しかった。ありがとうございました –

関連する問題