Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 27
Registered: ‎09-03-2012
My Device: Blackberry Playbook
My Carrier: None
Accepted Solution

QML custom control...can I have a property?

hi

I have created a simple custom control, but I want to be able to set the height of it when I create it.

Currently I can set the preferredHeight of each child control within the custom control but it seems wrong.

I feel I should set a property on the control then all my child controls use this to set their height.

But I can't find any example like this or any mention of a custom property; can I create my own property to store this in qml, then child controls (buttons, images) use that property to define their height?

many thanks in advance

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: QML custom control...can I have a property?

You can do things like this. Sorry I don't have a documentation reference offhand:

import bb.cascades 1.0

Container {
    id: root
    property real height: Infinity

    Label {
        text: "My Label"
        preferredHeight: root.height
    }

    Container {
        background: Color.Red
        preferredHeight: root.height
    }
}

That's obviously a contrived example but it should get you started.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 27
Registered: ‎09-03-2012
My Device: Blackberry Playbook
My Carrier: None

Re: QML custom control...can I have a property?

Perfect! Thanks Peter