I'm trying to write a topbar for my application that should contain mainly the app logo (a small image) and the app title (just text). Moreover, I'd like this topbar to automatically resize according to the window's height.
I'm new to QML, but I suppose that I should wrap these components inside a Row
or a RowLayout
component. This is my sample code:
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
}
*/
}
}
I tell to the Row
component that its height should follow the logo's height, and to the Image
(logo) component that its height should be 1/20th of the Rectangle
(mainwindow) component.
Using a Row
container, the code behaves as expected but I get an annoying warning (QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row. Row will not function.
) and I have to do a lot of anchoring. Conversely, if I use a RowLayout
container, I can remove most of the anchors but the Image
completely ignores its height
attribute (but the text still resizes correctly). So the questions are:
- is this a bug of the
RowLayout
component? I'm using Qt-5.1.0-Beta with Android support, so this could be an explanation - how can I use a
Row
component without using anchors in its children and thus avoid the warning? - I'm missing something important or I'm almost on the right track but I have to bear with this beta of Qt until a stable version is released?