[Solved] ComboBoxStyle: QtQuick.Controls and QtQuick.Controls.Styles



  • I'm trying to style a ComboBox. The documentation, see "here":http://qt-project.org/doc/qt-5.1/qtquickcontrolsstyles/qml-qtquick-controls-styles1-comboboxstyle.html, lacks an example and I cannot find anything about it. Anyone tried this?

    The following code gives an error on the ComboBoxStyle: could not resolve the prototype 'AbstractStyle' of 'Style' (M301)

    @import QtQuick 2.1
    import QtQuick.Controls 1.0
    import QtQuick.Controls.Styles 1.0
    ...

    ComboBox {
    id:comboBox
    width: 200
    model: ListModel {
    id: cbItems
    ListElement { text: "Banana"; color: "Yellow" }
    ListElement { text: "Apple"; color: "Green" }
    ListElement { text: "Coconut"; color: "Brown" }
    }

            style: ComboBoxStyle {
                background: Rectangle { color: "blue" }
                control: comboBox                
                }
            }
        }
    

    ...
    @



  • At least one of the problems seem to be that you are trying to assign control yourself. The control property is implicitly set when you assign the style and is a read only property. I am not sure why you are getting the error message though but removing the control assignment makes it work for me.



  • Thank you for your reply.

    The control assignment was code I put in in desperation... forgot to remove it when posting - sorry!

    However, the fact that it worked for you, gave me the idea to create a new project. I've inserted the same code, and it now works. In the old project it simply complains about the style and gives the same error as before!?

    It works now, and I dismissed the old project moving on in the new...



  • Perhaps you were launching the project with qmlviewer instead of qmlscene (qquick 1 vs qquick2) or something similar? If this is the only file, I can't really think of any other reasons why it would work to create a new project file.



  • Would the ComboBox it self then work, but the styling not? I'll see if I can recreate the issue...



  • No that does not make sense. Do let me know if you find out what's different between the two projects though. Environment settings, import paths etc.



  • Sure will...



  • I've recreated the files (luckily in the bin) and reopened the project. It now works. I have no idea of what happened, and why I cannot reproduce the error.

    In the meantime I have also rebooted Qt Creator (it hang - otherwise I would not have done this). Maybe the issue was related to that as well? (Qt Creator was not rebooted before I got it working in the new project, so it was not the reboot only that did it)

    Again, thanks for your help.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.