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. Forward all properties to child.
Qt 6.11 is out! See what's new in the release blog

Forward all properties to child.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 824 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.
  • D Offline
    D Offline
    davidwedel
    wrote on last edited by
    #1

    Hello all, been learning qml over the last several months. Searched some on this, haven't found anything.

    Item{// secondary homemade component to be used in main window
        id: iconButtonColor
        width: 120
        height: 90
        IconButton{// original homemade component to be used in main window
            id: iconButton
        }
    }
    

    So IconButton is a homemade component. I would like to by default forward all properties in iconButtonColor to IconButton, unless declared otherwise. I already know how to set individual properties using alias. But IconButton has a lot of properties, and I don't want to have to link them all individually.
    Any help will be much appreciated! Thanks.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      inogeni
      wrote on last edited by
      #2

      Hi,

      I hope i understood correctly your requirements, but what about instead of have your component IconButton as a nested component, what about having it as top level component ?

      for instance :

      * inside IconButton.qml*
      Item{
        id: root
        prop1 : "default value"
        prop2 : 10
        etc...
      }
      
      *inside IconButtonColor.qml*
      
      IconButton{
        id : root
        prop1: "default value for icon button color component" 
      }
      

      in your main.qml, you can use directly the component IconButtonColor , and set some of the properties

      *inside Main.qml*
      
      IconButtonColor {
        id: iconButtonColor
        prop2 : 20
      }
      

      i hope it help :)

      D 1 Reply Last reply
      0
      • I inogeni

        Hi,

        I hope i understood correctly your requirements, but what about instead of have your component IconButton as a nested component, what about having it as top level component ?

        for instance :

        * inside IconButton.qml*
        Item{
          id: root
          prop1 : "default value"
          prop2 : 10
          etc...
        }
        
        *inside IconButtonColor.qml*
        
        IconButton{
          id : root
          prop1: "default value for icon button color component" 
        }
        

        in your main.qml, you can use directly the component IconButtonColor , and set some of the properties

        *inside Main.qml*
        
        IconButtonColor {
          id: iconButtonColor
          prop2 : 20
        }
        

        i hope it help :)

        D Offline
        D Offline
        davidwedel
        wrote on last edited by
        #3

        @inogeni
        I'll have to think about that a little! So to explain a little more, IconButton{} is a Button{}, with an Icon in the middle(and a bunch of color settings). The team I'm working with decided it would be best to have button be the base, so we could use the default properties, without having to create our own.
        But as we went on, we started needing more and more variations (IconButtonTransparent, an IconButton with text in the button, all one color buttons, one with the text on the side, one with the text outside the button, etc). And since these are all fairly close to the same, it seemed like maybe they should all be based on IconButton{}.

        The text outside button is the real issue. If we keep the component base as button, then I have to anchor the text totally outside its parent. Which is fine until I put it in a layout, and everything starts overlapping. If I set the base (or root) component to Item{}, with Text{}, and IconButton{} siblings inside it, then every button action has to be set as an alias in Item{}.

        I hope that makes sense! You can view the whole project here if you want.
        https://github.com/torriem/QtAgOpenGPS
        Might be interesting if you're a farmer:).

        GrecKoG 1 Reply Last reply
        0
        • D davidwedel

          @inogeni
          I'll have to think about that a little! So to explain a little more, IconButton{} is a Button{}, with an Icon in the middle(and a bunch of color settings). The team I'm working with decided it would be best to have button be the base, so we could use the default properties, without having to create our own.
          But as we went on, we started needing more and more variations (IconButtonTransparent, an IconButton with text in the button, all one color buttons, one with the text on the side, one with the text outside the button, etc). And since these are all fairly close to the same, it seemed like maybe they should all be based on IconButton{}.

          The text outside button is the real issue. If we keep the component base as button, then I have to anchor the text totally outside its parent. Which is fine until I put it in a layout, and everything starts overlapping. If I set the base (or root) component to Item{}, with Text{}, and IconButton{} siblings inside it, then every button action has to be set as an alias in Item{}.

          I hope that makes sense! You can view the whole project here if you want.
          https://github.com/torriem/QtAgOpenGPS
          Might be interesting if you're a farmer:).

          GrecKoG Online
          GrecKoG Online
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          @davidwedel It seems like the problem comes solely from the text outside button.

          How do you want it to work? The button + text should be one item with sensible implicit width and height for both?

          Could you try having the Text as a child of the Button and set an inset on the button so its background and contentItem leave some space on one side?

          Something like this : 63724381-af12-4b55-960e-4d94285b188c-image.png
          Note that the inset doesn't seem to be correctly supported by the content item so I had to add a rightPadding there. This might depends on your Controls Style.

          Also note that clicking on "World" does trigger the button.

          D 1 Reply Last reply
          0
          • GrecKoG GrecKo

            @davidwedel It seems like the problem comes solely from the text outside button.

            How do you want it to work? The button + text should be one item with sensible implicit width and height for both?

            Could you try having the Text as a child of the Button and set an inset on the button so its background and contentItem leave some space on one side?

            Something like this : 63724381-af12-4b55-960e-4d94285b188c-image.png
            Note that the inset doesn't seem to be correctly supported by the content item so I had to add a rightPadding there. This might depends on your Controls Style.

            Also note that clicking on "World" does trigger the button.

            D Offline
            D Offline
            davidwedel
            wrote on last edited by
            #5

            @GrecKo
            Ended up going with this. Added a

             MouseArea{
                    id: catcher
                    anchors.top: parent.top
                    anchors.bottom: backgroundRect.top
                    anchors.right: parent.right
                    anchors.left: parent.left
                    onClicked: ("")
            }
            

            to catch the clicks above the button (or slider technically I guess. Button will come later...

            Thanks a lot for the help both of you!!

            1 Reply Last reply
            0
            • D davidwedel has marked this topic as solved on

            • Login

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