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
New Developer
Posts: 2
Registered: ‎07-21-2012
My Device: null
My Carrier: null
Accepted Solution

Create a new instance of a control in qml?

I want to add a button to a Container when another button is pressed.

 

How do I create the button? .create doesn't work , neither does new Button.

 

Is this possible?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Create a new instance of a control in qml?

There's no dynamic creation in QML.

 

However you can create the container with the button then just hide it with the visibility or opacity properties and show it again when your button is pressed. The cookbook example is useful for showing how this works.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

Re: Create a new instance of a control in qml?

Put the other button into attachedObjects.

Inside onClicked: of the first button just call something like:
containerId.add(button2Id);

Keep in mind: containerId and button2Id are defined by you as id values!!!!
--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development
Developer
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

Re: Create a new instance of a control in qml?

[ Edited ]

Or create Q_INVOKABLE method (let's say foo()) inside C++ code. Then put the object of class containing that method into context under specific name (again foo). Then call that method foo.foo() in onClicked signal.

In C++ you are capable of calling insert and other Container's metods too that are not Q_INVOKABLE.

--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development