Important: Please read the Qt Code of Conduct -

QML - property url question

  • I'm playing around with QML, below is a simple component

    Rectangle {
    id: rectangle1
    property string imageOn: "some filepath"
    property string imageOff: "some filepath"
    property string textMessage: "Submit"

        BorderImage {
        id: border_image1
        visible: !mouse_area1.pressed
        anchors.fill: parent
        source: parent.imageOn
    BorderImage {
        id: border_image2
        anchors.fill: parent
        visible: mouse_area1.pressed
        source: parent.imageOff


    Using QT Creator, If I drag this component and put it on another QML file in designer view the designer will show all the properties fine. I'd like the imageOn and imageOff properties to be set in the Designer by having the user choose a file, not by typing in a long file path. Is there anyway to do this?


    [EDIT: code formatting, please wrap in @-tags, Volker]

  • Try with

    property url imageOn: "some filepath"

    Also as this is a separate component I think it's better to use

    property alias imageOn: border_image1.source

  • Thanks for the reply, but in the designer I was still forced to enter a string using both methods.
    I was hoping it would show a file dialog.

  • When I set a property in a qml file like property url image: "some filepath" when I go in the designer it doesn't create a file dialog for the property. How can I set a property for a component that asks the user to choose from a file via the file dialog?

    Maybe this is not possible yet, but the image component and the border image component has the user choose a file through a dialog box for the source.

  • Merged this topics because they are about the same question.
    Please don't double post, but add your procedings or extra questions in the same post.

  • Eddy you are a good moderator, but you have no answers for my question. :-)

  • Moderators

    I don't believe this is supported in the designer yet for user-defined components, as far as I know. You can always add a feature request for it.

Log in to reply