Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Creating an Alias for a QML Type Member
QtWS25 Last Chance

Creating an Alias for a QML Type Member

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 4 Posters 1.2k Views
  • 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.
  • M Offline
    M Offline
    medelson
    wrote on last edited by
    #1

    I was wanting to create a Button Component with a fixed background and a variable label. Something like:
    @
    Button {
    property alias buttonLabel: styleLabel.label
    style: ButtonStyle {
    id: styleLabel
    label: Row { }
    background: Rectangle { ... }
    }
    }
    @

    Is it possible to create a property alias for "label"? I can't seem to find the correct syntax to do this. Thanks!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      morte
      wrote on last edited by
      #2

      You probably need to make alias for Row's id or something inside Row

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        What is the issue you are facing. What you are using the correct syntax.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        2
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          bq. Is it possible to create a property alias for “label”?

          I guess it won't work as the Component which it refers to would not have been initiated.
          If your purpose is to dynamically change the label's component you can create a property Component and the assign it a Component when you call it.
          eg:
          @
          MyButton.qml

          Item {
          property Component myComp
          Button {
          style: ButtonStyle {
          id: styleLabel
          label: myComp
          background: Rectangle { ... }
          }
          }
          }

          Main.qml

          MyButton {
          myComp: Qt.createComponent("labelDelegate1.qml")
          }

          MyButton {
          myComp: Qt.createComponent("labelDelegate2.qml")
          }
          @

          Hope this helps...

          157

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved