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

[SOLVED] Combobox styling



  • How to use ComboboxStyle::background property? I tried this but it`s not working

    Rectangle {
        id: mainRect
    
        width: 500
        height: 500
    
        ListModel{
            id: dataModel
            ListElement{ text: "Day" }
            ListElement{ text: "Week" }
            ListElement{ text: "Month" }
            ListElement{ text: "Year" }
        }
    
        ComboBox {
            id: box
            model: dataModel
    
            style: ComboBoxStyle{
                background: Rectangle{
                    color: "red"
                }
    
                label: Text{
                    text: control.currentText
                }
            }
            anchors.centerIn: parent
        }
    }
    

    I see only text in output (not clickable). What i`m doing wrong?


  • Moderators

    @xumuk Provide implicitWidth and implicitHeight for the Rectangle.

    implicitWidth: 120
    implicitHeight: 20
    

  • Moderators

    @xumuk Please mark it as solved if it worked so that others may understand that it has solution.