在bb10上实现后退按钮

时间:2013-07-04 07:06:33

标签: c++ qml blackberry-10

我有一个导航窗格,我在main.qml中禁用了后退按钮,但我想再次向应用程序的某些部分显示后退按钮。我该如何实现?这是我的cpp

pane = qml->createRootObject<NavigationPane>();

    // Set created root object as the application scene
    app->setScene(pane);

    qml->setContextProperty("cppObj", this);

}

void ApplicationUI::onLoginClicked() {
    // create scene document from buttonclicked.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///projects.qml").parent(this);
    qml->setContextProperty("cppObj", this);
    Page* root = qml->createRootObject<Page>();
    pane->push(root);
}

void ApplicationUI::onAddClicked() {
    // create scene document from buttonclicked.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///addprojects.qml").parent(this);
    Page* root = qml->createRootObject<Page>();
    pane->push(root);
}

这是我禁用后退按钮的主要内容

NavigationPane {
    backButtonsVisible: false }

如何将后退按钮激活到应用的某个部分?

1 个答案:

答案 0 :(得分:1)

假设您有以下代码:

起始页

import bb.cascades 1.0

NavigationPane {
    id: navPane

    Page {
        Container {
            horizontalAlignment: HorizontalAlignment.Fill
            verticalAlignment: VerticalAlignment.Fill
            layout: DockLayout {
            }
            Button {
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
                text: "Next Page"
                onClicked: {
                    var nextPage = page.createObject();
                    navPane.push(nextPage);
                }
            }
        }
    }

    attachedObjects: [
        ComponentDefinition {
            id: page
            source: "NextPage.qml"
        }
    ]
}

下一页:

import bb.cascades 1.0

Page {
    // disables backButton (not peeking)
    paneProperties: NavigationPaneProperties {
            backButton: ActionItem {
            enabled: false
        }
    }

    // [0]
    Container {
        horizontalAlignment: HorizontalAlignment.Fill
        verticalAlignment: VerticalAlignment.Fill
        layout: DockLayout {
        }
        Button {
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            text: "Prev page"
            onClicked: {
                var page = navPane.pop();
                if (page)
                    page.destroy();
            }
        }
    } // [0]

    // hides navigation bar
    onCreationCompleted: {
        navPane.backButtonsVisible = false;
    }
}

然后,您可以使用backButton

中的此代码完全禁用NextPage.qml
onCreationCompleted: {
    navPane.backButtonsVisible = false;
}

或者,如果您希望导航窗格可见但仅禁用“后退”按钮,请在同一NextPage.qml文件中使用以下内容:

paneProperties: NavigationPaneProperties {
    backButton: ActionItem {
        enabled: false
    }
}

另外,不要忘记peekEnabled属性。使用peek BB10功能,用户可以使用滑动手指移动而不触摸屏幕上的任何按钮在兄弟页面之间移动。

可以用类似的方式完成:

onCreationCompleted: {
    navPane.peekEnabled = false;
}

希望它有所帮助。