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

QML Button Text disappears while scrolling the listview.



  • Hi, Whenever I am scrolling my listview with Buttons inside it, sometimes the button text disappears, How can i fix this?



  • @mantra hi
    Giving your OS, qt version, compiler and code snippet that shows the issue may help



  • Yep sure,
    OS: Windows 10
    Qt Version: Qt Creator 4.10.1 - Based on Qt 5.13.1 (MSVC 2017, 32 bit)
    Compiler: I am using mingw64
    Code Snippet:

                  Grid {
                                    id: gridID
                                    anchors.bottom: componentAbove.bottom
                                    anchors.left: componentAbove.left
                                    anchors.leftMargin: componentAbove.iLeftMargin
                                    anchors.bottomMargin: 23
                                    width: parentComponent.width
                                    spacing: 15
                                    columns: 3
    
                                    Repeater {
                                        id:buttonsRepeater
                                        model: buttonList
    
                                        Button {
                                            height: 72
                                            property string strBtnColor: "white"
                                            property string strBtnFontColor: "black"
                                            text: "modelText"
                                            background: Rectangle {
                                                radius: 16
                                                border.color: "black"
                                                border.width: 2
                                                color: strButtonColor
                                            }
                                            leftPadding: 40
                                            rightPadding: 40
                                            font.pixelSize: 36
                                            font.styleName:strFontRegular
                                            font.bold: false
                                            property int clickDuration: 70
                                            onClicked: {
                                                    strBtnFontColor = "white"
                                                    strBtnColor = "green"
                                                    clickTimer.start();
                                                }
                                            }
    
                                            Timer {
                                                id:  clickTimer
                                                interval: parent.clickDuration
                                                running: false
                                                repeat: false
                                                onTriggered: {
                                                    clickTimer.stop();
                                                    strBtnColor = "white"
                                                    strBtnFontColor = "black"
                                                }
                                            }
                                        }
                                    }
                                }
    

    This is inside ListView , so i have dynamic buttons w.r.t my model but when i am scrolling my list, buttons text dissappear!



  • @mantra said in QML Button Text disappears while scrolling the listview.:

    This is inside ListView

    What do you mean by that ? Is this code used as your Listview Delegate ?

    Please try to provide a runnable code and show how it is used in a listview ?

    Also you can use the highlighted property with a ColorAnimation or States instead of the Timer to change the aspect of the button after a click



  • @LeLev I tried using States as well, I am still facing the same issue, whenever I am scrolling the text inside the buttons disappear, and once i click over any button I get the text back, but i want button text to be there all the time.



  • @mantra hi you did not answer my 2 questions

    @LeLev said in QML Button Text disappears while scrolling the listview.:

    What do you mean by that ? Is this code used as your Listview Delegate ?
    Please try to provide a runnable code and show how it is used in a listview ?



  • Hey @LeLev , Thank you being a help, I didn't answer your 2 questions coz i felt issue is not related to any of them, I tried setting one property and it got resolved.

    clip: true
    

    If there was something in code, I know you could have resolved it. Thanks.


Log in to reply