NavigationPane从C ++ BB10弹出

时间:2013-08-28 19:24:42

标签: c++ blackberry-10

我现在只在C ++中创建我的应用程序,我创建了NavigationPane并添加了我需要的视图的容器。它工作正常,但我想捕获一个单击的按钮,使NavigationPane弹出当前页面并推送不同的(在运行时制作)页面。

如何实现,我尝试使用信号,但我认为我没有得到它如何工作的信号和QT_SLOTS,在NavigationPane的情况下,它没有像QT_SLOT那样的方法。

任何建议都将受到赞赏。

3 个答案:

答案 0 :(得分:2)

首先,您需要将clicked()的{​​{1}}信号连接到Button的{​​{1}}位置。它应该是这样的:

pop()

此页面关于buttons可能有助于您了解如何处理此问题。为了更好地理解如何将对象连接在一起,您可能还需要查看信号和插槽文档。

然后您必须在弹出后创建并推送新页面。要做到这一点,您只需将NavigationPane的{​​{1}}插槽连接到将执行此操作的自定义功能。

// 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);

有关使用NavigationPane来堆叠页面的详细信息,请参阅this page

答案 1 :(得分:2)

---------------------尝试这个-------------

从我的github示例中获取示例应用程序以供查询....

https://github.com/svmrajesh/BB-10-Cascades/tree/master/MY%20APPS/stackNavigation


  1. 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. 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();
              }
    
            }
          }
       }
    

    / * -------------使用此代码如果后退按钮可见性为“True”-----------------

    paneProperties: NavigationPaneProperties {
    
        backButton: ActionItem {
            title: "Back"
         // imageSource: "asset:///back.png"
            onTriggered: {
                navigationPane.pop();
            }
            }
      } */
    }
    

    3.last page

         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();
                }
    
               }
             }
          }
        }
    

    ------------添加更多使用此代码导航的页面--------------------------- -

    -------------复制此代码并运行..如果需要,从上面的链接获取示例应用程序------

答案 2 :(得分:0)

你检查过这个吗? 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,但内部没有任何内容,如果你运行它,你会得到一个黑屏,添加一个页面(主页 - 第0页)使用push:
      navigationPane->push(Page::create() .content(Label::create("First page")));   

要添加一个新页面,它可以返回到页面0,我们只需按下再次使用Push,Remeber包括后退按钮返回:
      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   
在NavigationPane中的指定索引处插入页面。

     

传递的页面不能为0,否则将被忽略。如果   页面已经存在于导航堆栈中,操作将会   失败。此操作不会触发过渡效果,即使是   页面被添加到堆栈的顶部。如果是过渡效果   期望,使用push()代替。将发出topChanged()信号   如果操作影响顶级节点。

     

参数

     

1-指数
    页面将放置的索引。如果指数< 0页面插入底部。如果指数>导航堆栈中的页数,它被添加到堆栈顶部   2-页
    要插入的页面不能为0.

     

自:BlackBerry 10.0.0




一个想法是

  

你可以使用:
      navigationPane.count()
要获取nagationPane堆栈中的当前页面,并使用:
   navigationPane.insert(navigationPane.count()-1, myPageToBeBack);
在当前页面和页面之间推送页面   前一个