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
Regular Contributor
Megha_9_dec
Posts: 56
Registered: ‎08-21-2012
My Device: BB10
My Carrier: RIM

How to set Application Menu in BB10?

[ Edited ]

I've set Menu programatically in my application. Application Menu works fine in portrait mode when i swipe down from top of the device. When I set orientation mode to landscape there's no response on swipe down from top.

 

Here's what I've coded in app.cpp file

 

 

QmlDocument *qml = QmlDocument::create("main.qml");
AbstractPane *root = qml->createRootNode<AbstractPane>();

Menu *menu;

QObject *aItem1 = root->findChild<QObject*>("aItem1");   // have created action  items in main.qml
ActionItem* mActionItem1;
mActionItem1 = qobject_cast<ActionItem *>(aItem1);

QObject *aItem2 = root->findChild<QObject*>("aItem2");
ActionItem* mActionItem2;
mActionItem2 = qobject_cast<ActionItem *>(aItem2);

QObject *aItem3 = root->findChild<QObject*>("aItem3");
ActionItem* mActionItem3;
mActionItem3 = qobject_cast<ActionItem *>(aItem3);

QObject *aItem4 = root->findChild<QObject*>("aItem4");
ActionItem* mActionItem4;
mActionItem4 = qobject_cast<ActionItem *>(aItem4);

QObject *aItem5 = root->findChild<QObject*>("aItem5");
ActionItem* mActionItem5;
mActionItem5 = qobject_cast<ActionItem *>(aItem5);

menu =
Menu::create().addAction(mActionItem1).addAction(mActionItem2).addAction(
mActionItem3).addAction(mActionItem4).addAction(
mActionItem5);

bb::cascades::Application::setMenu(menu);

Application::setScene(root);

 

 

 

inside main.qml 

 

import bb.cascades 1.0

NavigationPane {
id: navigationPane
Page {
content: Container {
background: Color.White
Label {
text: ""
}
}
actions: [
ActionItem {
id: aItem1
objectName: "aItem1"
imageSource: "asset:///images/user_guide.png"

// ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
navigationPane.deprecatedPushQmlByString("userguide.qml");
}
},..................

 

Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: How to set Application Menu in BB10?

Thank you for finding and clearly describing this issue.

Please vote for https://www.blackberry.com/jira/browse/BBTEN-192

 

Stuart

Please use plain text.
Super Contributor
Meghasanghvi
Posts: 306
Registered: ‎08-10-2010
My Device: Not Specified

Re: How to set Application Menu in BB10?

Hi smacmartin,

Do we need to make custom application menu or in future update of BB10 we have resolve this issue?

Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: How to set Application Menu in BB10?

The menu is there: I've seen it on some of the swipes in landscape.  It seems to be the swipe that is the issue.  You should not have to adjust the menu if you turn sideways -- the menu is attached to your application, not to the page, so if you adjust the UI for the current orientation that shouldn't affect the menu.

 

Stuart

Please use plain text.
Developer
helex
Posts: 279
Registered: ‎02-14-2012
My Device: Nokia N950 / BB Playbook
My Carrier: -

Re: How to set Application Menu in BB10?

Thanks a lot for your example. I was going crazy because I were unable to connect a signal using the example from the official documentation. With your code it works just great.

 

A small improvement. In my opinion it is more elegant to use directly ActionItem Objects:

 

In your .h:

ActionItem *mActionItem;

 In your .cpp code:

 

Menu *menu = Menu::create();
mActionItem = root->findChild<ActionItem*>("ActionItemTest");
menu->addAction(mActionItem);

// accessable:
mActionItem->setTitle("Settings");

Application::setMenu(menu);
Application::setScene(root);

 

And I have used a TabbedPane in my code and were unable to add a ActionItem to it. So I added it like this:

 

  attachedObjects: [
        ActionItem {
            id: aActionItem
            objectName: "ActionItemTest"
            imageSource: "test.png"
            onTriggered: {
                logic.ButtonPressed()
            }
        }
    ]

 Just in case somebody is facing the same problem. :smileyhappy:

 

Please use plain text.
Developer
cyndrilla
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: How to set Application Menu in BB10?

Hi All,

 

I have a doubt ,can we change the background color of action item.If it so how can we change?

plzz help needed urgently.

 

Thanks

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: How to set Application Menu in BB10?

According to docs there is no property that would allow you to change background color of ActionItem

Please use plain text.
Developer
cyndrilla
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: How to set Application Menu in BB10?

Hi,

 

Yes according to the docs there is no property,but is there is any other way to change the default background color.

 


Thanks

Please use plain text.