Results 1 to 1 of 1

Thread: Page layout is fine as StackView initialItem, incorrect when pushed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Page layout is fine as StackView initialItem, incorrect when pushed

    Consider the following boilerplate main.cpp:

    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QQmlApplicationEngine>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QGuiApplication app(argc, argv);
    7.  
    8. QQmlApplicationEngine engine;
    9. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    10. if (engine.rootObjects().isEmpty())
    11. return -1;
    12.  
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    and main.qml:

    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Window 2.0
    3. import QtQuick.Controls 2.1
    4.  
    5. Window {
    6. visible: true
    7. width: 640
    8. height: 480
    9.  
    10. StackView {
    11. id: stack
    12.  
    13. anchors.fill: parent
    14. initialItem: Qt.resolvedUrl("ZorkView.qml")
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    Here is ZorkView:

    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Controls 2.1
    3. import QtQuick.Layouts 1.1
    4.  
    5. Page {
    6. header: ToolBar {
    7.  
    8. }
    9.  
    10. ColumnLayout {
    11. anchors.fill: parent
    12.  
    13. Text {
    14. text: qsTr("Zork 1!")
    15. }
    16. Text {
    17. text: qsTr("Zork 2!")
    18. }
    19. Item {
    20. Layout.fillHeight: true
    21. }
    22. Text {
    23. text: qsTr("Zork 3!")
    24. }
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Controls 2.1
    3.  
    4. Page {
    5. header: ToolBar {
    6.  
    7. }
    8.  
    9. Button {
    10. anchors.centerIn: parent
    11. text: "Click me"
    12.  
    13. onClicked: stack.push(Qt.resolvedUrl("ZorkView.qml"))
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. import QtQuick 2.5
    2. import QtQuick.Controls 2.1
    3. import QtQuick.Layouts 1.1
    4.  
    5. Item {
    6. ColumnLayout {
    7. anchors.fill: parent
    8. spacing: 0
    9.  
    10. ToolBar {
    11. Layout.fillWidth: true
    12. }
    13.  
    14. Text {
    15. text: qsTr("Zork 1!")
    16. }
    17. Text {
    18. text: qsTr("Zork 2!")
    19. }
    20. Item {
    21. Layout.fillHeight: true
    22. }
    23. Text {
    24. text: qsTr("Zork 3!")
    25. }
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    Have I stumbled on a bug after all...?
    Last edited by Urthas; 28th June 2017 at 00:31.

Similar Threads

  1. Replies: 2
    Last Post: 20th October 2017, 14:38
  2. StackView get index or views page
    By KeineAhnung in forum Newbie
    Replies: 2
    Last Post: 18th November 2014, 22:03
  3. qt pushed icon and widgetbox
    By giugio in forum Qt Programming
    Replies: 0
    Last Post: 9th November 2012, 10:26
  4. Replies: 1
    Last Post: 4th May 2011, 08:49
  5. Qt 3 on CentOS 5: page size incorrect
    By agajania in forum Installation and Deployment
    Replies: 0
    Last Post: 30th April 2009, 23:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.