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. Add QML component to inner component. How?
Forum Updated to NodeBB v4.3 + New Features

Add QML component to inner component. How?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 792 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

    Hello all!
    Is there any way to add QML component to inner component inside of custom component?
    For example I have:

    • CustomComponent.qml
    CustomComponent {
    	...
    	Column {
    		id: oColumn;
    
    		// Add here from outside
    
    		Rectangle{id: rectangle1}	
    		Rectangle{id: rectangle2}
    		Rectangle{id: rectangle3}
    	}
    }
    
    • Main.qml
    ApplicationWindow {
    	CustomComponent {
    		Rectangle{id: rectangle1}	
    		Rectangle{id: rectangle2}
    		Rectangle{id: rectangle3}
    	}
    }
    

    When I am using CustomComponent {} in Main.qml and addig rectangle how to add not to CustomComponent but to Column that is inside of CustomComponent? Is there option through property o something else?

    1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

      Set default property contentData:

      CustomComponent {
      	...
              default property alias contentData: oColumn.data
      	Column {
      		id: oColumn
              }
      }
      
      B 1 Reply Last reply
      1
      • IntruderExcluderI IntruderExcluder

        Set default property contentData:

        CustomComponent {
        	...
                default property alias contentData: oColumn.data
        	Column {
        		id: oColumn
                }
        }
        
        B Offline
        B Offline
        bogong
        wrote on last edited by bogong
        #3

        @IntruderExcluder Thx. That's what I forgotten "default" and "data". And it's working only if there are one component to add. If there multiple to add it's not working. Only if there adding like array, something like this:

        ApplicationWindow {
        	CustomComponent {
        		oColumn: [
        			Rectangle{id: rectangle1},	
        			Rectangle{id: rectangle2},
        			Rectangle{id: rectangle3}
        		]
        	}
        }
        

        And "default" not required. Issue closed.

        1 Reply Last reply
        0
        • IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on last edited by
          #4

          Multiple components in my case can be added as well:

          ApplicationWindow {
              CustomComponent {
                  Rectangle { }
                  Rectangle { }
                  Rectangle { }
              }
          }
          
          B 1 Reply Last reply
          0
          • IntruderExcluderI IntruderExcluder

            Multiple components in my case can be added as well:

            ApplicationWindow {
                CustomComponent {
                    Rectangle { }
                    Rectangle { }
                    Rectangle { }
                }
            }
            
            B Offline
            B Offline
            bogong
            wrote on last edited by bogong
            #5

            @IntruderExcluder What if you have 2 Columns? And you need to do it for both of them?

            1 Reply Last reply
            0
            • IntruderExcluderI Offline
              IntruderExcluderI Offline
              IntruderExcluder
              wrote on last edited by
              #6

              I'd prefer to separate such logic into different components.

              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