Page layout is fine as StackView initialItem, incorrect when pushed
Consider the following boilerplate main.cpp:
Code:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.
load(QUrl(QStringLiteral
("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
and main.qml:
Code:
import QtQuick 2.5
import QtQuick.Window 2.0
import QtQuick.Controls 2.1
Window {
visible: true
width: 640
height: 480
StackView {
id: stack
anchors.fill: parent
initialItem: Qt.resolvedUrl("ZorkView.qml")
}
}
Here is ZorkView:
Code:
import QtQuick 2.5
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1
Page {
header: ToolBar {
}
ColumnLayout {
anchors.fill: parent
Text {
text: qsTr("Zork 1!")
}
Text {
text: qsTr("Zork 2!")
}
Item {
Layout.fillHeight: true
}
Text {
text: qsTr("Zork 3!")
}
}
}
Everything looks exactly as it should when run.
However, when the initialItem is changed to HomeView -- which pushes ZorkView when the user clicks a button -- then ZorkView looks wrong, i.e., the column layout fills its parent irrespective of the toolbar, which therefore appears to hide the first two lines of text. (The third is placed correctly, as before.) Resizing the window corrects the problem. I duplicated this result using a simple red rectangle instead of a ColumnLayout and its contents.
For completeness, here is HomeView:
Code:
import QtQuick 2.5
import QtQuick.Controls 2.1
Page {
header: ToolBar {
}
Button {
anchors.centerIn: parent
text: "Click me"
onClicked: stack.push(Qt.resolvedUrl("ZorkView.qml"))
}
}
Note that I am running Qt 5.9 on a OS X El Capitan. This was not a problem with Qt 5.8!
It's not hard to stumble across this issue, so I'm disturbed that I can't seem to find anything about it. I strongly suspect that I'm missing something really basic and stupid, perhaps related to Controls versus Controls 2. If anyone has any insights or suggestions, I'd be very grateful!
update: Ha! Changing ZorkView from a Page to an Item that mimics a Page works! See below:
Code:
import QtQuick 2.5
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1
Item {
ColumnLayout {
anchors.fill: parent
spacing: 0
ToolBar {
Layout.fillWidth: true
}
Text {
text: qsTr("Zork 1!")
}
Text {
text: qsTr("Zork 2!")
}
Item {
Layout.fillHeight: true
}
Text {
text: qsTr("Zork 3!")
}
}
}
Have I stumbled on a bug after all...?