02-18-2013 05:24 PM
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);
02-19-2013 01:15 AM
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
Dishooom
02-19-2013 03:24 AM
In QML this works.
Container {
background: Color.create("#FF00FF00")
}
02-19-2013 03:28 AM
Yes, in QML but in C++ ?
The point was to be able to change different "themes"(colors) of application through menu.
02-19-2013 03:59 AM
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
02-19-2013 04:05 AM - edited 02-19-2013 04:29 AM
This should also work:
container1->setBackground(Color::fromARGB(0xff996633));
http://developer.blackberry.com/cascades/reference
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.
02-19-2013 10:39 AM
02-19-2013 11:14 AM