Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Different delegates in TableViewColumn depending on data
Qt 6.12 LTS is out! See what's new in the release blog

Different delegates in TableViewColumn depending on data

Scheduled Pinned Locked Moved Solved QML and Qt Quick
tableviewdelegateqt 5.12
5 Posts 3 Posters 3.5k 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.
  • SebastianMS Offline
    SebastianMS Offline
    SebastianM
    wrote on last edited by SebastianM
    #1

    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
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      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
      https://www.pthinks.com

      1 Reply Last reply
      0
      • SebastianMS Offline
        SebastianMS Offline
        SebastianM
        wrote on last edited by
        #3

        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
        0
        • GrecKoG Online
          GrecKoG Online
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          You could use DelegateChooser

          1 Reply Last reply
          1
          • SebastianMS Offline
            SebastianMS Offline
            SebastianM
            wrote on last edited by
            #5

            Cool, that's what I was looking for.

            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
            • Unsolved