我现在只在 C++ 中创建我的应用程序,我创建 NavigationPane 并添加带有我需要的视图的容器。它工作正常,但我想捕获一个单击的按钮以使 NavigationPane 弹出当前页面并推送一个不同的(在运行时制作的)页面。
如何实现它,我尝试使用信号,但我认为我没有了解信号和 QT_SLOTS 的工作方式,在 NavigationPane 的情况下,它没有 QT_SLOT 那样的方法。
任何建议将被认真考虑。
我现在只在 C++ 中创建我的应用程序,我创建 NavigationPane 并添加带有我需要的视图的容器。它工作正常,但我想捕获一个单击的按钮以使 NavigationPane 弹出当前页面并推送一个不同的(在运行时制作的)页面。
如何实现它,我尝试使用信号,但我认为我没有了解信号和 QT_SLOTS 的工作方式,在 NavigationPane 的情况下,它没有 QT_SLOT 那样的方法。
任何建议将被认真考虑。
You first need to connect the clicked()
signal of your Button
to the pop()
slot of your NavigationPane
. It should look like this:
// Connect the button's clicked() signal to the navigation pane's
// pop() slot.
bool connectResult = QObject::connect(myButton,
SIGNAL(clicked()),
myPane,
SLOT(pop()));
// Use the Q_ASSERT() function to test the return value and
// generate a warning message if the signal slot connection
// wasn’t successful.
Q_ASSERT(connectResult);
// Indicate that the variable connectResult isn't used in the
// rest of the app to prevent a compiler warning.
Q_UNUSED(connectResult);
This page about buttons might help you understand how to handle this. To better understand how to connect objects together, you might also want to have a look at a the signals and slots documentation.
You then have to create and push your new page after the pop. To do that, you simply have to connect the popTransitionEnded (bb::cascades::Page *page)
slot of your NavigationPane
to your custom function that will do the job.
bool connectResult = QObject::connect(myPane,
SIGNAL(popTransitionEnded(bb::cascades::Page*)),
this,
SLOT(createNewPageAndPushIt(bb::cascades::Page*)));
Q_ASSERT(connectResult);
Q_UNUSED(connectResult);
See this page for more details about the usage of NavigationPane to stack pages.
- - - - - - - - - - -尝试这个 - - - - - - -
从我的 github 示例中获取示例应用程序以供您查询....
https://github.com/svmrajesh/BB-10-Cascades/tree/master/MY%20APPS/stackNavigation
main.qml:(第一页)
import bb.cascades 1.0
NavigationPane {
id: navigationPane
backButtonsVisible: false
peekEnabled: false
Page
{
id: rootPage
Container {
background: Color.LightGray
layout: DockLayout {
}
Label {
text: "First page"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
}
}
actions: [
ActionItem {
title: "Next page"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
var page = pageDefinition.createObject();
navigationPane.push(page);
}
attachedObjects: ComponentDefinition {
id: pageDefinition
source: "PageTwo.qml"
}
}
]
}
onPopTransitionEnded: {
page.destroy();
}
}
2.第二页
import bb.cascades 1.0
Page {
id: pageTwo
Container {
background: Color.Gray
layout: DockLayout {
}
Label {
text: "Second page"
horizontalAlignment: HorizontalAlignment.Center
}
Container {
layout: StackLayout {
}
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
Button {
text: qsTr("Next Page")
imageSource: "asset:///images/picture1thumb.png"
onClicked: {
// show detail page when the button is clicked
var page = getSecondPage();
console.debug("pushing detail " + page)
navigationPane.push(page);
}
property Page secondPage
function getSecondPage() {
if (! secondPage) {
secondPage = secondPageDefinition.createObject();
}
return secondPage;
}
attachedObjects: [
ComponentDefinition {
id: secondPageDefinition
source: "PageTwoOne.qml"
}
]
}
Button {
text: "Previous Page"
onClicked: {
navigationPane.pop();
}
}
}
}
/* ------------- 如果后退按钮可见性为“真”,则使用此代码------
paneProperties: NavigationPaneProperties {
backButton: ActionItem {
title: "Back"
// imageSource: "asset:///back.png"
onTriggered: {
navigationPane.pop();
}
}
} */
}
3.最后一页
import bb.cascades 1.0
Page {
id: pageTwoone
Container {
background: Color.DarkGray
layout: DockLayout {}
Label {
horizontalAlignment: HorizontalAlignment.Center
text: "Last Page"
}
Container {
layout: StackLayout {}
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
Button {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: qsTr("Goto Home Page")
onClicked: {
// show detail page when the button is clicked
navigationPane.navigateTo(rootPage);
}
}
Button {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: qsTr("Goto Back")
onClicked: {
// show detail page when the button is clicked
navigationPane.pop();
}
}
}
}
}
------------ 添加更多页面以使用此代码导航----------------------------
-------------复制此代码并运行.. 如果需要,请从上面的链接获取示例应用程序------
你检查过这个吗? https://developer.blackberry.com/native/reference/cascades/bb__cascades__navigationpane.html
NavigationPane* navigationPane; // Global var to change current Page with push/pop
void initializeNavigationPane()
{
ActionItem* nextAction = ActionItem::create()
.title("Next page")
.onTriggered(this, SLOT(pushPage()));
navigationPane = NavigationPane::create();
QObject::connect(navigationPane, SIGNAL(popTransitionEnded(bb::cascades::Page*)),
this, SLOT(popFinished(bb::cascades::Page*)));
// Put a new page
navigationPane->push(Page::create()
.content(Label::create("First page"))
.addAction(nextAction, ActionBarPlacement::OnBar));
Application::instance()->setScene(navigationPane);
}
void popFinished(bb::cascades::Page* page){
delete page;
}
//You have to connect this method when you want a new Page pushed.
Q_SLOT void pushPage(){
ActionItem* backAction = ActionItem::create()
.title("Previous page")
.imageSource(QUrl("asset:///back.png"))
.onTriggered(navigationPane, SLOT(pop()));
navigationPane->push(Page::create()
.content(Label::create("Second page"))
.paneProperties(NavigationPaneProperties::create()
.backButton(backAction)));
}
解释:
对象 NavigationPane 的一个实例允许通过推送/弹出效果将当前页面更改为其他页面(参见图片):developer.blackberry.com/native/files/reference/cascades/images/navigation_pane_push_pop.png
你必须初始化:
navigationPane = NavigationPane::create();
并告诉应用程序你将使用这个实例来改变页面:
Application::instance()->setScene(navigationPane);
现在你的应用程序有一个 NavigationPane,但里面什么都没有,如果你运行它,你会得到一个黑屏,添加一个页面(主页面 - page0)使用推送:
navigationPane->push(Page::create() .content(Label::create("First page")));
要添加一个可以返回页面0的新页面,我们只需再次推送使用推送,请记住包含返回按钮以返回:
navigationPane->push(Page::create() .content(Label::create("Second page")) .paneProperties(NavigationPaneProperties::create() .backButton(ActionItem::create() .title("Previous page") .imageSource(QUrl("asset:///back.png")) //You should add manually this image. .onTriggered(navigationPane, SLOT(pop()))));
Q_INVOKABLE void insert (intindex, bb::cascades::Page *page ) https://developer.blackberry.com/native/reference/cascades/bb__cascades__NavigationPane.html#function-insert-index-page
在指定索引处插入页面在导航窗格中。传递的页面不能为0,否则会被忽略。如果页面已经存在于导航堆栈中,则操作将失败。该操作不会触发过渡效果,即使页面被添加到栈顶。如果需要过渡效果,请改用 push()。如果操作影响顶部节点,将发出 topChanged() 信号。
参数
1- index
将放置页面的索引。如果索引 < 0,则页面插入底部。如果索引 > 导航堆栈中的页数,则将其添加到堆栈顶部。
2- page
要插入的页面,不能为 0。自:黑莓 10.0.0
您可以使用:
navigationPane.count()
获取 nagationPane 堆栈中的当前页面,并使用:在当前页面和上一个页面之间推送页面
navigationPane.insert(navigationPane.count()-1, myPageToBeBack);