[SOLVED] Problem with properties when importing QtQuick.Controls 1.1



  • Hello all,

    i have a problem with a Button component and properties when I import QtQuick.Controls 1.1 .
    This is my Button.qml
    @
    import QtQuick 2.0

    Rectangle{
    property color buttonColor: "white"
    border.color: "black"
    border.width: 2
    property string buttonText: "default"
    Text{
    id: buttonLabel
    text: buttonText
    anchors.centerIn: parent;
    anchors.verticalCenterOffset: -1
    }

    signal buttonClick()
    onButtonClick: {
        console.log(buttonLabel.text + " clicked" )
    }
    
    MouseArea{
        id: buttonMouseArea
    
        anchors.fill: parent //anchor all sides of the mouse area to the rectangle's anchors
        //onClicked handles valid mouse button clicks
        onClicked: buttonClick()
    }
    
    color: buttonMouseArea.pressed ? Qt.darker(buttonColor, 1.5) : buttonColor
    

    }
    @

    And this is the snippet where i use it
    @
    Rectangle {
    id: outerBox
    color: "green"
    width: 0.9 * parent.width
    height: 0.2 * parent.height
    anchors.bottom: parent.bottom
    anchors.left: parent.left
    anchors.horizontalCenter: parent.horizontalCenter

        Button {
            id: testButton
            width: 0.1 * parent.width
            height: width
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            anchors.rightMargin: 0.05 * parent.width
            anchors.bottomMargin: anchors.rightMargin
            text: "Test"
            buttonText: "Test"
            //onButtonClick:
    
        }
    
    }
    

    @

    Above this snippet there is another rectangle which has a slider, therefore I have the following imports:
    @
    import QtQuick 2.0
    import QtQuick.Controls 1.1
    @

    As soon as is import QtQuickControls it complains that there is no property buttonText and i cant assign a onButtonClick.
    What is conflicting? The text property sets a labeling of the button, but why isn't buttonText working?

    Thank you.

    Regards


  • Moderators

    I suspect you have a conflict right there: a Button element exists in QtQuick controls already. "Link":http://qt-project.org/doc/qt-5.1/qtquickcontrols/qml-qtquick-controls1-button.html. Either rename your button or maybe import is with an alias (not sure if that works for QML files).



  • Thank you!
    That was quite easy. Renaming solved the problem.


Log in to reply
 

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