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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Regular Contributor
skyhawk92
Posts: 53
Registered: ‎02-04-2013
My Carrier: Simobil

Container setting background

Hi guys,

 

anyone have any idea why setting a background to container like this, would prevent application to start(application closes before it fully starts) ?

 

Page *appPage = root->findChild<Page*>("mainPage");
    	Container *container1 = appPage->findChild<Container*>("firstContainer");
    	container1->setBackground(Color::Green);

 

Please use plain text.
Developer
dishooom
Posts: 103
Registered: ‎12-31-2012
My Carrier: Verizon

Re: Container setting background

The setBackground() expects an argument of ImagePaint or ColorPaint type and not a Color.

 

ColorPaint class is used for retrieving the colors used in  fields in BB' s native theme. Such as the textColor used in SystemDefaults. Specific RGB values cannot be used here at the moment.

 

http://developer.blackberry.com/cascades/reference/bb__cascades__colorpaint.html

 

Dishooom

Please use plain text.
Developer
oliver_kranz
Posts: 180
Registered: ‎09-18-2009
My Carrier: O2

Re: Container setting background

In QML this works.

 

Container {
    background: Color.create("#FF00FF00")
}

 

Please use plain text.
Regular Contributor
skyhawk92
Posts: 53
Registered: ‎02-04-2013
My Carrier: Simobil

Re: Container setting background

Yes, in QML but in C++ ?

 

The point was to be able to change different "themes"(colors) of application through menu.

Please use plain text.
Developer
dishooom
Posts: 103
Registered: ‎12-31-2012
My Carrier: Verizon

Re: Container setting background

One way to get this done is by adding a javascript function in your qml file to set the background property of the container as shown

 function setColorYellow() {
            bellContainer.background = Color.Yellow
        }

 Then, from the CPP file you can invoke this method for the container as

  Container* con = bb::cascades::Application::instance()->findChild<Container*>("bellContainer");
    QMetaObject::invokeMethod(con, "setColorYellow");

May be there's an easier way to get this done, but this is one that does work for me.

 

 - Dishooom

Please use plain text.
Developer
Zmey
Posts: 919
Registered: ‎12-18-2012

Re: Container setting background

[ Edited ]

This should also work:

container1->setBackground(Color::fromARGB(0xff996633));

http://developer.blackberry.com/cascades/reference/bb__cascades__color.html

 

Or using a builder:

 

Container *someContainer = Container::create().background(Color::fromARGB(0xff996633));

There are also predefined values for colors like Color::Red.

 

The code in first post looks correct:

Container *container1 = appPage->findChild<Container*>("firstContainer");
    	container1->setBackground(Color::Green);

It could crash because Container with id 'firstContainer' wasn't found among the children of appPage.

You can check that container1 is not NULL by logging it's value or setting a breakpoint on next line and running the app in debugger. Also ensure that appPage itself is not NULL.

 

Please use plain text.
Regular Contributor
skyhawk92
Posts: 53
Registered: ‎02-04-2013
My Carrier: Simobil

Re: Container setting background

Yep, appPage is NULL but I don't have any idea why ?

In QML it has objectName: mainPage
then in C++ I call Page *appPage = root->findChild<Page*>("mainPage");
Please use plain text.
Regular Contributor
skyhawk92
Posts: 53
Registered: ‎02-04-2013
My Carrier: Simobil

Re: Container setting background

If i findChild a button it works normaly( is not NULL),
but if try to find Page or Container they are NULL.
Please use plain text.