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. How to update component(text) in itemDelegate at the run time?
Forum Updated to NodeBB v4.3 + New Features

How to update component(text) in itemDelegate at the run time?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 456 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rajesh_Mandava
    wrote on last edited by
    #1

    import QtQuick 2.13
    import QtQuick.Controls 2.13

    Item {
    id: menu
    width: parent.width
    height: parent.height

    SwipeView{
        id:menuSwipe
        x:20
        y:100
        height: parent.height
        width: 600
        clip: true
        orientation: Qt.Horizontal
        currentIndex: 0
    	    Item {
            id: pageOne
            Rectangle{
                id: rect1
                height: 144
                width: 132
                anchors.left: parent.left
                anchors.leftMargin: 18
                anchors.top: parent.top
                anchors.topMargin: 44
                color: "Transparent"
    			
             ListView {
                id: submenu1
                width: parent.width
                height: parent.height
                spacing: 12
                x:28
                y:216
                anchors.left: parent.left
                anchors.right:parent.right
                anchors.leftMargin: 28
                anchors.rightMargin: 28
                model: modelOne
    		delegate: Component {
                       ItemDelegate{
    
                        height: 68
                        width: 396
                        anchors.horizontalCenter: parent.horizontalCenter
                        Rectangle {
                            anchors.fill: parent
                            radius: 10
                            color: "transparent"
    						
    		        Image {
                                id: arrowImage
                                relativeSource: "image.png"
                                anchors.right: parent.right
                                anchors.verticalCenter: parent.verticalCenter
                                anchors.rightMargin: 20
                            }
    						
    						    Text {
                                id:  title
                                text: model.title
                                width: parent.width
                                height: parent.height
                                anchors.left: parent.left
                                anchors.leftMargin: 28
                                font.family: Theme.fontFamily
                                font.pixelSize: 32
                                horizontalAlignment: Text.AlignLeft
                                verticalAlignment: Text.AlignVCenter
                                color: "#ffffff"
    
                            }
                        }
                        onClicked: {
                            console.log("onClicked!")
    
                            }
    			}
    		}
    	}
        }
        }
       }
    
        ListModel {
        id: modelOne
        ListElement {
            title: title1
    		
        }
        ListElement {
            title: title2
           
        }
        ListElement {
            title: title3
            
        }
    }
    function signalUpdate()
    {
    	//disable the title1 button and change color of text
    }
    

    }

    How to update the title color of text component and disable the title1 button at the run time based upon signalUpdate.
    Please help.

    Note:This is a sample code of my problem.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      This is described in depth in the documentation: https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html

      A ListModel is generally speaking static - for dynamic models it's generally better to go with C++ models.

      But still, ListModel does have some functions you can use to modify the model at runtime, see "Methods" section in the docs: https://doc.qt.io/qt-5/qml-qtqml-models-listmodel.html

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rajesh_Mandava
        wrote on last edited by
        #3

        I don't want to update the listmodel, instead would like to disable the title1 button in itemDelegate.

        sierdzioS 1 Reply Last reply
        0
        • F Offline
          F Offline
          flowery
          wrote on last edited by flowery
          #4

          Updating via C++ model is best way to do it .Since you don't want it , you can define a signal for listview and write connections inside delegate.When you want to disable ,emit the signal and handle the functionality inside connections based on some condition matching for title1.But you should remember the connections will be executed for all delegates. For ex:

          ListView {
          id: view
          model: modelOne
          anchors.fill: parent
          signal update()
          delegate: Text {
          text: title
          Connections {
          target: view
          onUpdate:{
          console.log("updated "+title)
          }
          }
          }
          }

          1 Reply Last reply
          1
          • R Rajesh_Mandava

            I don't want to update the listmodel, instead would like to disable the title1 button in itemDelegate.

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @Rajesh_Mandava said in How to update component(text) in itemDelegate at the run time?:

            would like to disable the title1 button in itemDelegate.

            That's a modification of the model. The delegate can't have any saved state - it only displays what the model tells it to. So even turning something on/off is a boolean property of the model - at least should be.

            (Z(:^

            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