主にアプリのロゴ (小さな画像) とアプリのタイトル (テキストのみ) を含むアプリケーションのトップバーを作成しようとしています。さらに、このトップバーをウィンドウの高さに応じて自動的にサイズ変更したいと考えています。
私は 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 のこのベータ版を我慢しなければなりませんか?