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
luisdr22
Posts: 20
Registered: ‎09-02-2013
My Device: Dev Alpha B
My Carrier: Claro Codetel

Re: click event on a container

a custom control can be a container?

 

Please use plain text.
Developer
slashkyle
Posts: 800
Registered: ‎10-16-2012
My Device: Red Z10, Dev Alpha C
My Carrier: Telus

Re: click event on a container

[ Edited ]

yes simply create a new qml file as a container, the name should start with an uppercase

 

example

MyCustomComponent.qml would be accessed like this in main.qml

 

MyCustomComponent {
      id: myCustomComponent
onTouch: {
if (event.isDown(){
//do something
}
} }

 

so now anytime you touch whatever you have in myCustomComponent it will do the action specified, this can be useful for having elements interact with main, but being able to keep the code separated.

 

also if you have a property in MyCustomComponent.qml it can be accessed in main like this

 

MyCustomConponent.qml

Container {
    id: root

    property bool somethingHappened
}

 

main.qml

MyCustomComponent {
      id: myCustomComponent
      onSomethingHappenedChanged: {
          if (!somethingHappened){
              console.log("somethingHappened is false")
          } else { 
              console.log("somethingHappened is true")
          }
     }
}

 or

main.qml

Container {
   id: root

   onCreationCompleted: {
        myCustomComponent.somethingHappened = true;
   }
}

 

*Useful Performance Tip

if the content you store in custom components such as this doesnt always need to be accessed it's best to apply some type of control delegation by either dynamically creating/destroying the content or using controlDelegate to manage that.  It's not neccesary but doing this will lead enhance performance because your app won't be using memory for things that it doesnt need.

https://developer.blackberry.com/native/documentation/cascades/best_practices/dynamic_qml/

Please use plain text.
Contributor
luisdr22
Posts: 20
Registered: ‎09-02-2013
My Device: Dev Alpha B
My Carrier: Claro Codetel

Re: click event on a container

may i ask you if this can be done on c++?

should i rather to use qml + c++ than plain c++?

 

many thanks! 

Please use plain text.
Developer
slashkyle
Posts: 800
Registered: ‎10-16-2012
My Device: Red Z10, Dev Alpha C
My Carrier: Telus

Re: click event on a container

you can interact with the component from c++ using object names, and you can interact with c++ from the custom component by using context properties.

 

I know dynamic qml components is something that can only be done in qml but that's because javascript works differently than c++.  From what i've been learning c++ esentially manages this itself as it starts from the beginning and continues to the end, then stops.

 

'Custom' components in c++ would essentially be similar to creating a separate set of .cpp & .hpp files for your function, like BPS Monitor, or QTimer

Please use plain text.
Contributor
luisdr22
Posts: 20
Registered: ‎09-02-2013
My Device: Dev Alpha B
My Carrier: Claro Codetel

Re: click event on a container

ok, so it can be done, i heard and saw that qml + c++ its easier to implement, and the documentation its better using both, ill read a bit about it, because my programs are plain c++ 

Please use plain text.
Developer
slashkyle
Posts: 800
Registered: ‎10-16-2012
My Device: Red Z10, Dev Alpha C
My Carrier: Telus

Re: click event on a container

[ Edited ]

If you're already working with pure c++ I would personally encourage that, as qml is susceptible to external access in some cases it's possible for users to get ahold of your bar file and expose the qml content

Please use plain text.
Contributor
luisdr22
Posts: 20
Registered: ‎09-02-2013
My Device: Dev Alpha B
My Carrier: Claro Codetel

Re: click event on a container

Ok, ill keep this app in c++ and the next app i will use both :smileyvery-happy:, ill try to implement your qml code on c++ and see if its possible :smileytongue:

Please use plain text.
Developer
BBSJdev
Posts: 5,986
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: click event on a container

You've set the solution to slashkyles answer but this is not the answer to your original OP question about TapHandlers and receiving container events.  Please set the solution to one that answers the actual question and in future if you want to change the question enter it in another thread.  I blame myself partially for suggesting not to subclass container, setting the thread off at a tangent.

 

I've asked a moderator to split the thread.

 

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
BBSJdev
Posts: 5,986
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: click event on a container

@slashkyle once again you've read something I've put and totally misinterpreted it as well as not answering the OP no wonder the original poster is confused. I meant this...

 

http://developer.blackberry.com/native/reference/cascades/bb__cascades__customcontrol.html


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

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Contributor
luisdr22
Posts: 20
Registered: ‎09-02-2013
My Device: Dev Alpha B
My Carrier: Claro Codetel

Re: click event on a container

you're right, how can i remove correct answer from a message? and its true, even thought i can use what he said, that doesnt fix my problem, if someone want help me or the comunity i can send the project...  if you need any information about this problem please post it.. because i know that this post will help others :smileyvery-happy:

Please use plain text.