Issues with stackview



  • Hey guys see this gif : https://s31.postimg.org/mjg6288wr/web.gif

    The issue that i have is that once webview is created/executed i am not able to get back my manage pages page .

    What i want is when i click on manage page tab again , i want to see manage pages page not webview

    code :

    search.qml(webview page )

    import QtQuick 2.6
    import QtQuick.Controls 2.0
    import QtWebView 1.1
    
    Pane {
        id: pane
    
    
    
    
        WebView{
            id:webview
            anchors.fill: parent
    
            Component.onCompleted: url = "http://en.wikitolearn.org/"
        }
    }
    

    manage_pages.qml ( manage page )

    import QtQuick 2.6
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 2.0
    
    
    Pane {
        padding: 0
    
        property var delegateComponentMap: {
            "page": itemDelegateComponent
    
        }
    
        Component {
            id: itemDelegateComponent
    
            ItemDelegate {
                text: labelText
                width: parent.width
            }
        }
    
    
    
    
    
    
        ColumnLayout {
            id: column
            spacing: 40
            anchors.fill: parent
            anchors.topMargin: 20
    
            Label {
                id: label1
                Layout.fillWidth: true
                wrapMode: Label.Wrap
                horizontalAlignment: Qt.AlignHCenter
                text: "Offline Pages "
            }
    
            ListView {
                id: listView
    
                Layout.fillWidth: true
                Layout.fillHeight: true
                clip: true
                model: ListModel {
                    ListElement { type: "ItemDelegate"; labelText: "page1" }
                    ListElement { type: "ItemDelegate"; labelText: "page2" }
                    ListElement { type: "ItemDelegate"; labelText: "page3" }
    
    
                }
                spacing: 5
    
                section.property: "type"
    
                delegate: Component{
    
                    Item{
                        id: aItem
                        width: listView.width //rowLayout.width. We got width from children elements before, now get width from listView
                        height: 30
    
                        RowLayout{
    
                            id: rowLayout
                            anchors.fill: parent
                            spacing: 10
    
                            Label{
                                id:page_name
                                padding: 10
                                text: labelText
                                Layout.fillWidth: true // !!! to fill most part of row width
    
                            }
    
    
                                Button{
    
                                    text: qsTr("Delete")
    
                                    id: delete_button
    
                                }
                                Button{
    
                                    text: qsTr("Update")
                                    id: update_button
                                }
    
    
    
                        }
                    }
                }
            }
    
    
    
    
    
    
    
    
    
            RowLayout{
                Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
    
                Button{
                    text:"Update All"
    
    
                }
                Button{
                    text:"Delete All"
                }
            }
        }
    }
    

    gallery.qml ( main.qml )

    import QtQuick 2.6
    import QtQuick.Layouts 1.3
    import QtQuick.Controls 2.0
    import QtQuick.Controls.Material 2.0
    import QtQuick.Controls.Universal 2.0
    import Qt.labs.settings 1.0
    import QtWebView 1.0
    
    
    ApplicationWindow {
        id: window
        width: 360
        height: 520
        visible: true
        title: "WikiToLearn"
    
    
    
    
        Settings {
            id: settings
            property string style: "Material"
        }
    
        header: ToolBar {
            Material.foreground: "white"
    
    
            RowLayout {
                spacing: 20
                anchors.fill: parent
    
                ToolButton {
                    contentItem: Image {
                        fillMode: Image.Pad
                        horizontalAlignment: Image.AlignHCenter
                        verticalAlignment: Image.AlignVCenter
                        source: "qrc:/images/drawer.png"
                    }
                    onClicked: drawer.open()
                }
    
                Label {
                    id: titleLabel
                    text: "WikiToLearn"
                    font.pixelSize: 20
                    elide: Label.ElideRight
                    horizontalAlignment: Qt.AlignHCenter
                    verticalAlignment: Qt.AlignVCenter
                    Layout.fillWidth: true
                }
    
                ToolButton {
                    contentItem: Image {
                        fillMode: Image.Pad
                        horizontalAlignment: Image.AlignHCenter
                        verticalAlignment: Image.AlignVCenter
                        source: "qrc:/images/menu.png"
                    }
                    onClicked: optionsMenu.open()
    
                    Menu {
                        id: optionsMenu
                        x: parent.width - width
                        transformOrigin: Menu.TopRight
    
                        MenuItem {
                            text: "Settings"
                            onTriggered: settingsPopup.open()
                        }
                        MenuItem {
                            text: "About"
                            onTriggered: aboutDialog.open()
                        }
                    }
                }
            }
        }
    
        Drawer {
        id: drawer
        width: Math.min(window.width, window.height) / 3 * 2
        height: window.height
    
        ColumnLayout {
               anchors.fill: parent
               Rectangle {
                   width: drawer.width
                   height: 50
    
                   TextField{
                       id: search_text
                       placeholderText: " Search WikiToLearn"
                       width: drawer.width
    
                       Image {
                           id: search_button
                           anchors.right: search_text.right
                           anchors.verticalCenter: search_text.verticalCenter
                           source: "qrc:/images/search.png"
                           MouseArea{
                               anchors.fill: search_button
                               onClicked: {
                                  loader.source = "qrc:/pages/search.qml"
                               }
                               Loader{
    
                                   id: loader
                                       anchors.fill: parent
    
                               }
    
    
                           }
                       }
    
                   }
               }
    
            ListView {
                id: listView
                currentIndex: -1
                Layout.fillWidth: true
                Layout.fillHeight: true
    
                delegate: ItemDelegate {
                    width: parent.width
                    text: model.title
                    highlighted: ListView.isCurrentItem
                    onClicked: {
                        if (listView.currentIndex != index) {
                            listView.currentIndex = index
                            titleLabel.text = model.title
                            stackView.replace(model.source)
                        }
                        drawer.close()
                    }
                }
    
                model: ListModel {
                    ListElement { title: "Get New Pages"; source: "qrc:/pages/get_new_pages.qml" }
                    ListElement { title: "Manage Pages"; source: "qrc:/pages/manage_pages.qml" }
    
    
                }
    
                ScrollIndicator.vertical: ScrollIndicator { }
            }
        }
    
    }
        StackView {
            id: stackView
            anchors.fill: parent
    
            initialItem: Pane {
                id: pane
                anchors.fill: parent
    
    
    
                Image {
                    id: logo
                    width: pane.availableWidth / 2
                    height: pane.availableHeight / 2
                    anchors.centerIn: parent
                    anchors.verticalCenterOffset: -50
                    fillMode: Image.PreserveAspectFit
                    source: "qrc:/images/wtl-logo.png"
                }
    
                Label {
                    text: "WikiToLearn wants to provide free, collaborative and accessible text books to the whole world \“knowledge only grows if shared\""
                    anchors.margins: 20
                    anchors.top: logo.bottom
                    anchors.left: parent.left
                    anchors.right: parent.right
                    horizontalAlignment: Label.AlignHCenter
                    verticalAlignment: Label.AlignVCenter
                    wrapMode: Label.Wrap
                }
    
    
    
            }
        }
    
        Popup {
            id: settingsPopup
            x: (window.width - width) / 2
            y: window.height / 6
            width: Math.min(window.width, window.height) / 3 * 2
            height: settingsColumn.implicitHeight + topPadding + bottomPadding
            modal: true
            focus: true
    
            contentItem: ColumnLayout {
                id: settingsColumn
                spacing: 20
    
                Label {
                    text: "Settings"
                    font.bold: true
                }
    
                RowLayout {
                    spacing: 10
    
                    Label {
                        text: "Style:"
                    }
    
                    ComboBox {
                        id: styleBox
                        property int styleIndex: -1
                        model: ["Default", "Material", "Universal"]
                        Component.onCompleted: {
                            styleIndex = find(settings.style, Qt.MatchFixedString)
                            if (styleIndex !== -1)
                                currentIndex = styleIndex
                        }
                        Layout.fillWidth: true
                    }
                }
    
                Label {
                    text: "Restart required"
                    color: "#e41e25"
                    opacity: styleBox.currentIndex !== styleBox.styleIndex ? 1.0 : 0.0
                    horizontalAlignment: Label.AlignHCenter
                    verticalAlignment: Label.AlignVCenter
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                }
    
                RowLayout {
                    spacing: 10
    
                    Button {
                        id: okButton
                        text: "Ok"
                        onClicked: {
                            settings.style = styleBox.displayText
                            settingsPopup.close()
                        }
    
                        Material.foreground: Material.primary
                        Material.background: "transparent"
                        Material.elevation: 0
    
                        Layout.preferredWidth: 0
                        Layout.fillWidth: true
                    }
    
                    Button {
                        id: cancelButton
                        text: "Cancel"
                        onClicked: {
                            styleBox.currentIndex = styleBox.styleIndex
                            settingsPopup.close()
                        }
    
                        Material.background: "transparent"
                        Material.elevation: 0
    
                        Layout.preferredWidth: 0
                        Layout.fillWidth: true
                    }
                }
            }
        }
    
        Popup {
            id: aboutDialog
            modal: true
            focus: true
            x: (window.width - width) / 2
            y: window.height / 6
            width: Math.min(window.width, window.height) / 3 * 2
            contentHeight: aboutColumn.height
    
            Column {
                id: aboutColumn
                spacing: 20
    
                Label {
                    text: "About"
                    font.bold: true
                }
    
                Label {
                    width: aboutDialog.availableWidth
                    text: "WikiToLearn wants to provide free, collaborative and accessible text books to the whole world.
    Our philosophy is synthetized in the sentence: “knowledge only grows if shared”"
                    wrapMode: Label.Wrap
                    font.pixelSize: 12
                }
    
                Label {
                    width: aboutDialog.availableWidth
                    text: "We provide a platform where learners and teachers can together complete,"
                        + "refine and re-assemble notes, lecture notes in order to create text books, "
                        + "tailored precisely to their needs, so that you can “stand on the shoulders of giants”"
                    wrapMode: Label.Wrap
                    font.pixelSize: 12
                }
            }
        }
    }
    

  • Moderators



  • hey @Wieland here is image : https://s31.postimg.org/mjg6288wr/web.gif

    P.S. updated on my post too


  • Moderators

    The runtime error is:

    qrc:/gallery.qml:159:25: QML Pane: StackView has detected conflicting anchors.

    What's at this line? Can you fix it?



  • at qrc:/gallery.qml:159:25: Pane

    code related to it :

    initialItem: Pane {
                   id: pane
                   anchors.fill: parent
    

    sreenshot : http://imgur.com/QiwATjv



  • SOLVED

     onClicked: {
                                  loader.source = "qrc:/pages/search.qml"
                                   stackView.push(loader.item)
                                   listView.currentIndex = -1
                               }
    

    Thanks @medyakovvit


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.