Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

TableView rowDelegate color is wrong when scroll



  • Hello guys,

    I'm using rowDelegate on simple tableView with code below:

    rowDelegate: Rectangle{
                    height:20*globalScaleFactor
                    border.color: "black"
                    border.width : 1
                    SystemPalette {
                        id: myPalette;
                        colorGroup: SystemPalette.Active
                    }
                    color: {
                        var baseColor = styleData.alternate?myPalette.alternateBase:myPalette.base
                        //return styleData.selected?myPalette.highlight:baseColor
                        if(styleData.row>-1){
                            var rowSelected=styleData.selected;
                            var hoverMouse=mouse_area.hovered;
                            var qty=parseInt(listView.model.get(styleData.row).quantity);
                            var esdPart=listView.model.get(styleData.row).esdPart;
                            var stockMini=parseInt(listView.model.get(styleData.row).stockMini);
                            var expirationdate=listView.model.get(styleData.row).expirationDate
                            var alarmDate =expirationdate!="N/A"?new Date(JS1.subMonth(Date.fromLocaleDateString(Qt.locale(),expirationdate,"dd/MM/yyyy"),1)):new Date();
                            //var time= new Date(expirationdate).getTime()
                            var dateCheck=alarmDate<new Date()
                            var qtyCheck=qty<=stockMini
                            if(rowSelected&& hoverMouse && !qtyCheck && !dateCheck)
                                return "green"
                            else if(rowSelected && !hoverMouse && !qtyCheck && !dateCheck && esdPart=="2" )
                                return "lightgreen"
                            else if(!rowSelected && qtyCheck && !hoverMouse && esdPart=="0" || !rowSelected && dateCheck && !hoverMouse && esdPart=="0")
                                return "red"
                            else if(!rowSelected && qtyCheck && hoverMouse || !rowSelected && dateCheck && hoverMouse && esdPart=="0")
                                return "darkred"
                            else if( !rowSelected && esdPart=="2" && !hoverMouse && !qtyCheck && !dateCheck)
                                return "aqua"
                            else if( !rowSelected && esdPart=="2" && hoverMouse && !qtyCheck && !dateCheck)
                                return "blue"
                            else if( !rowSelected && hoverMouse && !qtyCheck && !dateCheck && esdPart=="0" )
                                return "gold"
                            else
                                return baseColor
    
                        }else{
                            return baseColor
                        }
                    }
                    MouseArea{
                        id:mouse_area
                        property bool hovered
                        propagateComposedEvents : false
                        hoverEnabled: true
                        anchors.fill:parent
                        onEntered: {
                            hovered=true
                        }
                        onExited: {
                            hovered=false;
                        }
                        onPressed: {mouse.accepted = false}
                    }
                }
    

    it is working almost fine but sometime, when I'm scrolling the view, the row has bad color until I hovering the row. What I did wrong?

    Thank you very much for your help

    Philippe


Log in to reply