Quantcast
Channel: Active questions tagged qtquick2 - Stack Overflow
Viewing all articles
Browse latest Browse all 107

Qt 5.15.2 item disappear when used in StackView

$
0
0

I have this QML files

//main.qml

import QtQuick 2.9import QtQuick.Window 2.2import QtQuick.Controls 2.2Window {    visible: true    width: 640    height: 480    title: qsTr("Hello World")    Component {        id: firstPage        BasePage {            bottomBar.rightButton.text: qsTr("Next")            bottomBar.rightButton.visible: true            bottomBar.visible: true            Button {                height: parent.height * 0.2                width: parent.width * 0.3                anchors.centerIn: parent                text: "NEXT"                onClicked: stackView.push(secondPage)            }        }    }    Component {        id: secondPage        BasePage {            onBackKeyPressed: stackView.pop()        }    }    StackView {        id: stackView        initialItem: firstPage        anchors.fill: parent    }}

//BasePage.qml

import QtQuick 2.9import QtQuick.Controls 2.2import QtQuick.Layouts 1.3Page {    default property alias content: contentItem.data    property alias bottomBar: bottomBar    signal bottomBarLeftButtonClicked()    signal bottomBarCentralButtonClicked()    signal bottomBarRightButtonClicked()    signal backKeyPressed()    id: basePageItem    focusPolicy: Qt.ClickFocus    Keys.onReleased: {        if(event.key !== Qt.Key_Back && event.key !== Qt.Key_Escape)            return;        backKeyPressed()        event.accepted = true    }    Rectangle {        id: background        anchors.fill: parent        ColumnLayout {            id: basePage            anchors.fill: parent            spacing: 0            Item {                id: contentItem                Layout.fillHeight: true                Layout.fillWidth: true            }            BottomBar {                id: bottomBar                Layout.preferredHeight: parent.height * 0.1                Layout.preferredWidth: parent.width                visible: leftButton.visible || centralButton.visible || rightButton.visible                onLeftButtonClicked: bottomBarLeftButtonClicked()                onCentralButtonClicked: bottomBarCentralButtonClicked()                onRightButtonClicked: bottomBarRightButtonClicked()            }        }    }}

//BottomBar.qml

import QtQuick 2.9import QtGraphicalEffects 1.0import QtQuick.Controls 2.2import QtQuick.Layouts 1.3Rectangle {    property alias leftButton: leftButton    property alias centralButton: centralButton    property alias rightButton: rightButton    signal leftButtonClicked()    signal centralButtonClicked()    signal rightButtonClicked()    id: bottomBar    color: "#fafafa"    ColumnLayout {        anchors.fill: parent        spacing: 0        LinearGradient {            Layout.preferredHeight: parent.height * 0.1            Layout.preferredWidth: parent.width            gradient: Gradient {                GradientStop { position: 0.0; color: "#fafafa" }                GradientStop { position: 1.0; color: "#d7d7d7" }            }        }        Item {            Layout.preferredHeight: parent.height * 0.9            Layout.preferredWidth: parent.width            RowLayout {                anchors.fill: parent                spacing: width * 0.02                Item {                    Layout.preferredHeight: parent.height                    Layout.preferredWidth: parent.width * 0.32                    BottomBarItem {                        id: leftButton                        visible: false                        anchors.fill: parent                        onClicked: bottomBar.leftButtonClicked()                    }                }                Item {                    Layout.preferredHeight: parent.height                    Layout.preferredWidth: parent.width * 0.32                    BottomBarItem {                        id: centralButton                        visible: false                        anchors.fill: parent                        onClicked: bottomBar.centralButtonClicked()                    }                }                Item {                    Layout.preferredHeight: parent.height                    Layout.preferredWidth: parent.width * 0.32                    BottomBarItem {                        id: rightButton                        anchors.fill: parent                        visible: false                        onClicked: bottomBar.rightButtonClicked()                    }                }            }        }    }}

//BottomBarItem.qml

import QtQuick 2.9import QtQuick.Controls 2.2Item {    property alias text: buttonText.text    signal clicked()    id: item    Column {        anchors.fill: parent        Item {            height: parent.height * 0.6            width: height            anchors.horizontalCenter: parent.horizontalCenter        }        Text {            id: buttonText            height: parent.height * 0.4            anchors.horizontalCenter: parent.horizontalCenter        }    }    MouseArea {        anchors.fill: parent        onClicked: item.clicked()    }}

When the program starts everything works well and the bottomBar is visible.
Then I click on the NEXT button -> second page is shown.
Then I go back to the first page and the bottom bar has disappeared.
Am I doing something wrong?


Viewing all articles
Browse latest Browse all 107

Trending Articles