Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Different delegates in TableViewColumn depending on data

    QML and Qt Quick
    tableview delegate qt 5.12
    3
    5
    952
    Loading More Posts
    • 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.
    • SebastianM
      SebastianM last edited by SebastianM

      In QTableView with custom delegate in createEditor I can provide any widget I want to display my data. I have access to model, so I test what data are inside and display them with different widget.

      How to achieve the same in TableView/TableViewColumn?

      	TableViewColumn{
      		title: "Value"
      		role: "propertyValue"
      		movable: false
      		delegate: {
      			type = propertiesTableView.model.data(propertiesTableView.model.index(styleData.row, styleData.column), 0x0100);
      			//styleData is not defined
      			console.log("Type value for row '"+styleData.row+"' is "+type)
      			if (type == 1) 
      				return NodePropertyDelegate.floatDelegate
      			else if (type == 2)
      				return 0
      

      I tried this - but styleData is not present, so I don't know how to get type from model.

      1 Reply Last reply Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        deletegate should be Component. In your code you are writing code directly.

        delegate : Rectangle {
              width:100;height:100;color:"blue"; 
              Text {
                 text : styleData.value
               }  
        }
        

        Any processing inside the delegate can be done with appropriate signal handler inside the signal handler of component.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply Reply Quote 0
        • SebastianM
          SebastianM last edited by

          Please take a look into sensor_explorer example (Qt 5.11+).
          There's part of code

                          itemDelegate: {
                              if (selectedItem && selectedItem.isWriteable)
                                  return editableDelegate;
                              return readOnlyDelegate;
                          }
          

          where code makes selection what to display as delegate depending on few properties of TableView.
          I'm referring to this kind of code to select which delegate to show.

          1 Reply Last reply Reply Quote 0
          • GrecKo
            GrecKo Qt Champions 2018 last edited by

            You could use DelegateChooser

            1 Reply Last reply Reply Quote 1
            • SebastianM
              SebastianM last edited by

              Cool, that's what I was looking for.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post