Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Referencing Column from a delegate



  • Hi,
    I am trying to reference a column in a SimpleRow delegate from a SimpleSection:

    import Felgo 3.0
    import QtQuick 2.9
    import QtQuick.Controls 2.5
    import QtQuick.Controls.Styles 1.4
    import QtQuick.LocalStorage 2.12
    import "Database.js" as JS
    
    App {
    
        AppListView {
            id: myListView
            anchors.fill: parent
    
            model: ListModel {
                id: listModel
            }
    
            delegate: SimpleRow {
                Column {
                    id: wordColumn
                    visible: false
    
                    AppText {
                        text: model.wordField
                        x: dp(10)
                    }
                }
            }
    
            section.property: "sectionField"
            section.delegate: SimpleSection {
                enabled: true
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        console.debug("letter clicked")
                        wordColumn.visible = !wordColumn.visible
                    }
                }
            }
        }
    
        Component.onCompleted: {
            JS.dbGetWordList()
        }
    }
    
    

    When I run it I get the following error message:
    ReferenceError: wordColumn is not defined
    I assume this is not the right way to reference it from SimpleSection. Please help me to make it correct. Thank you for your help.


  • Moderators

    @gabor53
    Thats because you trying to reference an id of an Component - which lives in its own context until an Item is created from it (which at the time the error occurs isn't the case yet in any runtime (parent) context.

    Anyway you should rather bind the visibility to a property of an Item which already exists, like on the AppListView itself, and toggle this property from the section.



  • Hi @raven-worx ,
    I bound the visibility to ApplistView. It works, but the whole page disappears when I click a section. Is there any other possible way of binding the visibility property? If possible to do this with SimpleSection please give me a little bit more detailed idea how to do it. Thank you for your help.


  • Moderators

    @gabor53
    i meant create a new custom property only for your purpose.


Log in to reply