Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using "parent->findChild<QObject*>("objectName")"function,return null,when I find a ItemDelegate QML
QtWS25 Last Chance

Using "parent->findChild<QObject*>("objectName")"function,return null,when I find a ItemDelegate QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daryl_X
    wrote on last edited by
    #1
    ListView {
                id: listView
                objectName: "mainListView"
                currentIndex: -1
                anchors.fill: parent
                anchors.top: parent.Top
                anchors.topMargin: 0.22*parent.height
    
                delegate: ItemDelegate {
                    id: mainItemDelegate
                    objectName: "mainItemDelegate"
                    width: parent.width
                    anchors.horizontalCenter: parent.horizontalCenter
    
                    Image {
                        width: 0.1*parent.width
                        height: 0.8*parent.height
                        anchors.left: parent.left
                        anchors.leftMargin: 0.1*parent.width
                        source: model.icon
                    }
                    Label {
                        width: 0.5*parent.width
                        height: parent.height
                        text: model.title
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
    
                    highlighted: ListView.isCurrentItem
                    onClicked: {
                        if (listView.currentIndex != index) {
                            listView.currentIndex = index
                            mainStackView.replace(model.source)
                            if(2==index)
                            {
                                mainMenu.drawerItemChanged(index)
    //                            toolBarTop.visible = fasle
                            }
                        }
                        mainDrawer.close()
                    }
                }
    

    This is my code in QML.

    Arvindhan PonnusamyA 1 Reply Last reply
    0
    • D Daryl_X
      ListView {
                  id: listView
                  objectName: "mainListView"
                  currentIndex: -1
                  anchors.fill: parent
                  anchors.top: parent.Top
                  anchors.topMargin: 0.22*parent.height
      
                  delegate: ItemDelegate {
                      id: mainItemDelegate
                      objectName: "mainItemDelegate"
                      width: parent.width
                      anchors.horizontalCenter: parent.horizontalCenter
      
                      Image {
                          width: 0.1*parent.width
                          height: 0.8*parent.height
                          anchors.left: parent.left
                          anchors.leftMargin: 0.1*parent.width
                          source: model.icon
                      }
                      Label {
                          width: 0.5*parent.width
                          height: parent.height
                          text: model.title
                          anchors.horizontalCenter: parent.horizontalCenter
                      }
      
                      highlighted: ListView.isCurrentItem
                      onClicked: {
                          if (listView.currentIndex != index) {
                              listView.currentIndex = index
                              mainStackView.replace(model.source)
                              if(2==index)
                              {
                                  mainMenu.drawerItemChanged(index)
      //                            toolBarTop.visible = fasle
                              }
                          }
                          mainDrawer.close()
                      }
                  }
      

      This is my code in QML.

      Arvindhan PonnusamyA Offline
      Arvindhan PonnusamyA Offline
      Arvindhan Ponnusamy
      wrote on last edited by
      #2

      @Daryl_X Refer the link which explains your query.
      https://forum.qt.io/topic/7401/problem-with-finding-qml-elements-placed-within-listview-s-delegate-from-c-code-resolved/5

      D 1 Reply Last reply
      0
      • Arvindhan PonnusamyA Arvindhan Ponnusamy

        @Daryl_X Refer the link which explains your query.
        https://forum.qt.io/topic/7401/problem-with-finding-qml-elements-placed-within-listview-s-delegate-from-c-code-resolved/5

        D Offline
        D Offline
        Daryl_X
        wrote on last edited by
        #3

        @Arvindhan-Ponnusamy I run the code run time,but still.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved