Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [Solved] Custom Component [propery alias VS ..]

    QML and Qt Quick
    2
    4
    2385
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Thanatos last edited by

      Maybe someone can suggest good approach:

      I wrote my own Component that is a button. Different text property for each Component can bet set by - property alias text: someId.text - but what about if i want each Component to react differently on onClicked event from MouseArea?

      1 Reply Last reply Reply Quote 0
      • A
        anselmolsm last edited by

        You can add a signal to your component then emit it in onClicked of your MouseArea.

        Something like this:

        Button:
        @
        Rectangle {
        width: 200
        height: 200

        signal buttonClicked()
        
        MouseArea {
            anchors.fill: parent
            onClicked: buttonClicked()
        }
        

        }
        @

        Then when you want to use this component with a different reaction when clicked:
        @
        Button {
        onButtonClicked: <your action here>
        }
        @

        Anselmo L. S. Melo (anselmolsm)

        1 Reply Last reply Reply Quote 0
        • T
          Thanatos last edited by

          Thanks man, this is great solution.

          1 Reply Last reply Reply Quote 0
          • A
            anselmolsm last edited by

            [quote author="Thanatos" date="1289674558"]Thanks man, this is great solution.[/quote]

            Yay! You're welcome :-)

            Anselmo L. S. Melo (anselmolsm)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post