主にアプリのロゴ (小さな画像) とアプリのタイトル (テキストのみ) を含むアプリケーションのトップバーを作成しようとしています。さらに、このトップバーをウィンドウの高さに応じて自動的にサイズ変更したいと考えています。
私は QML を初めて使用しますが、これらのコンポーネントをRowまたはコンポーネント内にラップする必要があると思いRowLayoutます。これは私のサンプルコードです:
import QtQuick 2.0
import QtQuick.Layouts 1.0
Rectangle
{
id: mainwindow
width: 1024
height: 600
Row
{
id: rowlayout
height: logoimage.height
spacing: 5
property int count: 3
anchors
{
left: parent.left
right: parent.right
top: parent.top
}
Image
{
id: logoimage
source: "qrc:/images/resources/images/icon.png"
height: mainwindow.height / 20
anchors.top: parent.top
anchors.left: parent.left
}
Text
{
id: logotext
text: qsTr("This is my logo text")
font.pixelSize: parent.height
font.family: "Sans Serif"
height: parent.height
verticalAlignment: Text.AlignVCenter
anchors.top: parent.top
anchors.left: logoimage.right
}
/*
Rectangle
{
id: otherrect
height: parent.height
color: "lightgreen"
anchors.top: parent.top
anchors.left: logotext.right
anchors.right: parent.right
}
*/
}
}
Rowコンポーネントの高さはロゴの高さに従うようにコンポーネントに指示し、 Image(ロゴ) コンポーネントには高さがRectangle(メインウィンドウ) コンポーネントの 1/20 になるように指示します。
コンテナーを使用するRowと、コードは期待どおりに動作しますが、迷惑な警告 ( QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row. Row will not function.) が表示され、多くのアンカーを行う必要があります。逆に、RowLayoutコンテナーを使用すると、ほとんどのアンカーを削除できますが、Imageその属性は完全に無視されheightます (ただし、テキストのサイズは正しく変更されます)。質問は次のとおりです。
RowLayoutこれはコンポーネントのバグですか?AndroidをサポートするQt-5.1.0-Betaを使用しているため、これが説明になる可能性がありますRow子にアンカーを使用せずにコンポーネントを使用して、警告を回避するにはどうすればよいですか?- 何か重要なものを見逃しているか、ほぼ正しい軌道に乗っていますが、安定版がリリースされるまで Qt のこのベータ版を我慢しなければなりませんか?