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 send value from model to delegate which is separate file?

How to send value from model to delegate which is separate file?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 387 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.
  • M Offline
    M Offline
    milan
    wrote on last edited by milan
    #1

    hello, I have troubles sending value from a GridView model to a delegate. I have delegate in a separate file because I would like to have some enhancement. I have remove some code to make code compact for viewing. The model is C++ model

        GridView {
            width: parent.width
            height: parent.height
            cellHeight: 250
            cellWidth: 250
            id: appGrid
            model: chmodel
            delegate: GaugeComponent{
            }
    
    // GaugeComponent
    Item {
    	function parseStrtoInt(str)
    	{
    		console.log("gauge string:"+str);
    		console.log("gauge float:"+parseFloat(str));
    		return parseFloat(str);
    	}
    	property real gaugevalue: parseStrtoInt(num) // num is data in the model
    
    	CircularGauge {
    		value: gaugevalue
    		anchors.centerIn: parent.Center
    		style: CircularGaugeStyle {
    			needle: Rectangle {
    				y: outerRadius * 0.15
    				implicitWidth: outerRadius * 0.03
    				implicitHeight: outerRadius * 0.9
    				antialiasing: true
    				color: Qt.rgba(0.66, 0.3, 0, 1)
    			}
    			tickmark: Rectangle {
    				visible: styleData.value < 80 || styleData.value % 10 == 0
    				implicitWidth: outerRadius * 0.02
    				antialiasing: true
    				implicitHeight: outerRadius * 0.06
    				color: styleData.value >= 80 ? "#e34c22" : "#e5e5e5"
    			}
    			minorTickmark: Rectangle {
    				visible: styleData.value < 80
    				implicitWidth: outerRadius * 0.01
    				antialiasing: true
    				implicitHeight: outerRadius * 0.03
    				color: "#e5e5e5"
    			}
    
    			tickmarkLabel:  Text {
    				font.pixelSize: Math.max(6, outerRadius * 0.1)
    				text: styleData.value
    				color: styleData.value >= 80 ? "#e34c22" : "#e5e5e5"
    				antialiasing: true
    			}
    			foreground: Item {
    				Rectangle {
    					width: outerRadius * 0.2
    					height: width
    					radius: width / 2
    					color: "#e5e5e5"
    					anchors.centerIn: parent
    				}
    			}
    		}
        }
    }
    
    T 1 Reply Last reply
    0
    • M milan

      hello, I have troubles sending value from a GridView model to a delegate. I have delegate in a separate file because I would like to have some enhancement. I have remove some code to make code compact for viewing. The model is C++ model

          GridView {
              width: parent.width
              height: parent.height
              cellHeight: 250
              cellWidth: 250
              id: appGrid
              model: chmodel
              delegate: GaugeComponent{
              }
      
      // GaugeComponent
      Item {
      	function parseStrtoInt(str)
      	{
      		console.log("gauge string:"+str);
      		console.log("gauge float:"+parseFloat(str));
      		return parseFloat(str);
      	}
      	property real gaugevalue: parseStrtoInt(num) // num is data in the model
      
      	CircularGauge {
      		value: gaugevalue
      		anchors.centerIn: parent.Center
      		style: CircularGaugeStyle {
      			needle: Rectangle {
      				y: outerRadius * 0.15
      				implicitWidth: outerRadius * 0.03
      				implicitHeight: outerRadius * 0.9
      				antialiasing: true
      				color: Qt.rgba(0.66, 0.3, 0, 1)
      			}
      			tickmark: Rectangle {
      				visible: styleData.value < 80 || styleData.value % 10 == 0
      				implicitWidth: outerRadius * 0.02
      				antialiasing: true
      				implicitHeight: outerRadius * 0.06
      				color: styleData.value >= 80 ? "#e34c22" : "#e5e5e5"
      			}
      			minorTickmark: Rectangle {
      				visible: styleData.value < 80
      				implicitWidth: outerRadius * 0.01
      				antialiasing: true
      				implicitHeight: outerRadius * 0.03
      				color: "#e5e5e5"
      			}
      
      			tickmarkLabel:  Text {
      				font.pixelSize: Math.max(6, outerRadius * 0.1)
      				text: styleData.value
      				color: styleData.value >= 80 ? "#e34c22" : "#e5e5e5"
      				antialiasing: true
      			}
      			foreground: Item {
      				Rectangle {
      					width: outerRadius * 0.2
      					height: width
      					radius: width / 2
      					color: "#e5e5e5"
      					anchors.centerIn: parent
      				}
      			}
      		}
          }
      }
      
      T Offline
      T Offline
      Tom_H
      wrote on last edited by
      #2

      @milan I assume num is not available? Try giving your delegate an id and accessing the model through the Gridview.view.model attached property.

      // GuageComponent
      Item {
        id: mydelegate
        property real gaugevalue: parseStrtoFloat(mydelegate.GridView.view.model.num)
        ...
      }
      
      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        Your program should work without any issue. Please confirm whether model has property call 'num'. If it exist it should work.

        What is not working ? What is the error you see ?

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

        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