如何在qml中关闭工作表?

时间:2013-08-06 10:57:10

标签: c++ splash-screen blackberry-10 blackberry-cascades

我想在用户点击应用程序图标时显示启动页面。为此,我创建了Sheet并附加到页面。 的 main.qml

import bb.cascades 1.0

Page {
    Container {
        Label {
            text: "Home page"
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
        }
    }
    attachedObjects: [
        Sheet {
            id: mySheet
            content: Page {
                Label {
                    text: "Splash Page / Sheet."
                }
            }
        }
    ]//end of attached objects
    onCreationCompleted: {

        //open the sheet
        mySheet.open();

        //After that doing some task here.
       ---------
       ---------
       ---------

       //Now I'm closing the Sheet. But the Sheet was not closed.
       //It is showing the Sheet/Splash Page only, not the Home Page
       mySheet.close();
    }
}//end of page

完成工作后,我想关闭工作表。所以我调用了close()方法。但是Sheet没有关闭。

如何在oncreationCompleted()方法或任何c ++方法中关闭工作表?

1 个答案:

答案 0 :(得分:1)

您试图在开始完成之前关闭Sheet(动画仍在运行),因此它会忽略关闭请求。您必须监控动画结束(opened()信号)以了解您的Sheet是否已打开。我会做那样的事情:

import bb.cascades 1.0

Page {
    Container {
        Label {
            text: "Home page"
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
        }
    }
    attachedObjects: [
        Sheet {
            id: mySheet
            property finished bool: false
            content: Page {
                Label {
                    text: "Splash Page / Sheet."
                }
            }
            // We request a close if the task is finished once the opening is complete
            onOpened: {
                if (finished) {
                    close();
                }
            }
        }
    ]//end of attached objects
    onCreationCompleted: {

        //open the sheet
        mySheet.open();

        //After that doing some task here.
       ---------
       ---------
       ---------

       //Now I'm closing the Sheet. But the Sheet was not closed.
       //It is showing the Sheet/Splash Page only, not the Home Page
       mySheet.finished = true;
       // If the Sheet is opened, we close it
       if (mySheet.opened) {
           mySheet.close();
       }
    }
}//end of page