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. Indefinite memory growth when using radius in Rectangle delegate.
Forum Updated to NodeBB v4.3 + New Features

Indefinite memory growth when using radius in Rectangle delegate.

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

    Hey, I have a TableView class with Rectangle and children as a delegate. I also have a selection model so my Rectangle changes color on selection. If I set radius to a value other than zero - memory usage of app grows indefinitely with every selection.
    Does anyone knows what causing this? I would appreciate any help!
    Here is my TableView code:

    import QtQuick
    import QtQuick.Controls
    import QtQuick.Layouts
    import DCStyle
    import "qrc:/DuneCat/imports/qml/components"
    
    
    ScrollView {
        id:scrollView
        property alias model : tableView.model
        ScrollBar.vertical: ScrollBar{
            id:scrollBar
            parent:scrollView
            anchors.topMargin: header.height
            anchors.top: parent.top
            anchors.bottom: parent.bottom
            anchors.right:parent.right
            }
    //    Button{
    //        onPressed: tableView.model.refresh()
    //        width: 100
    //        z:5
    //        height: 60
    //        anchors.top: parent.top
    
    //    }
    
        TableView
        {
            id:tableView
            anchors.fill:parent
            property int lastSelected
            topMargin: header.height
            delegate:viewDelegate
            boundsBehavior: Flickable.StopAtBounds
            selectionBehavior: TableView.SelectRows
            selectionModel: ism
            model: ProcessHistoryModel
            columnWidthProvider: function(column) {
                var role
                if(index === 2 || index === 3)
                    role = Qt.UserRole
                else
                    role = Qt.DisplayRole
                return Math.min(200,model.columnWidth(column,role,10))
                }
            property bool headerBinded: false
            Connections{
                target: model
                function onModelAboutToBeReset(){
                    var temp = ism.selectedRows(0)[0]
                    tableView.lastSelected = temp.row
                    console.log("on model about to be reset. Index = ",tableView.lastSelected)
    
                }
                function onModelReset(){
                    console.log("on model reset. Index = ", tableView.lastSelected)
    
                    if(tableView.lastSelected)
                        ism.select(tableView.model.index(tableView.lastSelected,0),
                                    ItemSelectionModel.SelectCurrent )
                }
            }
    
        }
    
        Connections{
            target: header
            function onPositioningComplete() {
                if(!tableView.headerBinded)
                {
                    tableView.columnWidthProvider = function(column){return header.repeater.itemAt(column).width}
                    tableView.forceLayout()
                    tableView.headerBinded = true
                }
                else
                    tableView.forceLayout()
            }
        }
    
        Rectangle
        {
            parent:scrollView
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.top: parent.top
            anchors.topMargin: header.height
            color: "darkgrey"
            height: 1
            width:parent.width
            z:10
        }
    
        Row{
            id:header
            parent:scrollView
            height: 30
            property alias repeater: colRepeater
            Repeater
            {
                id: colRepeater
                model:tableView.model.columnCount()
                DCTableHeaderColumn{
                    id:col
                    height:parent.height
                    fontPointSize: 10
                    width:{
                        var role
                        if(index === 2 || index === 3)
                            role = Qt.UserRole
                        else
                            role = Qt.DisplayRole
                        return Math.min(200,tableView.model.columnWidth(index,role,10))
                    }
                    label:tableView.model.headerData(index,Qt.Horizontal,Qt.DisplayRole)
                    onSorting: {
                        for(var i = 0; i < colRepeater.model; i++)
                            if(i !== index)
                                colRepeater.itemAt(i).stopSorting()
                        tableView.model.sort(index, state === "up" ? Qt.AscendingOrder : Qt.DescendingOrder)
                    }
                }
            }
        }
    
        Component {
            id: viewDelegate
            Rectangle {
                id:wrapper
                property alias textDelegate: textDel
                implicitHeight: textDel.implicitHeight+15
                color: selected ? "lightblue" : "white"
                radius: 10
                required property bool selected
                required property int row
                required property bool current
                Text{
                    id: textDel
                    z: 3
                    width:parent.width
                    text:{
                        if(column === 2 || column === 3)
                            return displayDate
                        else
                            return display
                    }
                    font.pointSize: 10
                    anchors.left: parent.left
                    anchors.leftMargin: 5
                    anchors.verticalCenter: parent.verticalCenter
                    elide: Text.ElideRight
                }
                MouseArea
                {
                    anchors.fill: parent
                    onClicked: {
                        if(!ism.isRowSelected(index))
                        {
                            ism.select(tableView.model.index(row,column),
                                       ItemSelectionModel.SelectCurrent | ItemSelectionModel.Rows | ItemSelectionModel.Clear)
                        }
                    }
                }
            }
        }
    
        ItemSelectionModel{
            id:ism
            model:tableView.model
        }
    
    }
    

    P.S. My Qt version is 6.5.1

    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