• Meego touch实现页面跳转和返回 狼人:


    前面写完了第一个Meego touch的程序,相信大家也看到Meego touch的界面风格,显示效果等等。不过却没有页面跳转,和返回等效果,那这篇文章就研究下,如何实现页面的跳转和返回?
    Meego touch默认会通过返回键或者退出键实现当前页面的关闭,并且返回到前一个页面。
    所以下面通过代码实现页面的跳转,最后效果如下图:

    当程序启动时,会显示第一个页面,点击上面的“Open second page”,则会跳转到第二个页面。
    在第二个页面点击返回按钮,则会关闭当前页面,跳回到第一个页面。

    主要代码介绍:
    main.cpp,程序入口,创建FirstPage的对象,然后使用page->appear(&window);window.show();使第一个页面显示

    #include <MApplication>
    #include
    <MApplicationWindow>
    #include
    "firstpage.h"

    int main(int argc, char **argv)
    {
    MApplication app(argc, argv);
    MApplicationWindow window;
    FirstPage
    *page = new FirstPage();

    page
    ->appear(&window);
    window.show();

    return app.exec();
    }

    FirstPage.cpp,第一个页面显示界面的创建,设置窗体标题,增加一个按钮,显示Open second page,然后通过connect(button, SIGNAL(clicked()), SLOT(openNextPage()))函数,使button点击之后,执行openNextPage函数。
    在openNextPage()函数里面,创建SecondPage对象,并调用appear方法显示。

    #include "firstpage.h"
    #include
    <MSceneManager>
    #include
    <MButton>

    FirstPage::FirstPage() : MApplicationPage(
    0)
    {
    QString title, buttonTitle,labelTitle;
    title
    = "First page";
    buttonTitle
    = "Open second page";

    setTitle(title);
    MButton
    *button = new MButton(buttonTitle);

    connect(button, SIGNAL(clicked()), SLOT(openNextPage()));
    setCentralWidget(button);
    }

    void FirstPage::openNextPage()
    {
    SecondPage
    *secondPage = new SecondPage();
    secondPage
    ->appear(scene(), MSceneWindow::DestroyWhenDismissed);
    }

    firstpage.h

    #ifndef FIRSTPAGE_H
    #define FIRSTPAGE_H

    #include
    <MApplicationPage>
    #include
    <secondpage.h>

    class FirstPage : public MApplicationPage {
    Q_OBJECT

    public:
    FirstPage();

    private slots:
    void openNextPage();
    };
    #endif

    SecondPage.cpp,第二个页面的创建,设置窗体标题,添加一个label,并显示I am in second page

    #include "secondpage.h"
    #include
    <MLabel>

    SecondPage::SecondPage() : MApplicationPage(
    0)
    {
    QString title, labelTitle;
    title
    = "Second page";
    labelTitle
    = "I am in second page";

    setTitle(title);
    setCentralWidget(
    new MLabel(labelTitle));
    }

    secondpage.h

    #ifndef SECONDPAGE_H
    #define SECONDPAGE_H

    #include
    <MApplicationPage>

    class SecondPage : public MApplicationPage {
    Q_OBJECT

    public:
    SecondPage( );
    };
    #endif

    在文件里启动终端,执行qmake -project,生成XXX.pro文件,打开文件,添加CONFIG+=meegotouch,保存退出。
    然后依次执行qmake,make。
    执行完make之后,则会在文件夹下面生成执行文件,通过sudo ./<程序名>,则就会显示出上图所出现的结果。

  • 相关阅读:
    基于Metaweblog API 接口一键发布到国内外主流博客平台
    uva144 Student Grants
    Uva 10452
    Uva 439 Knight Moves
    Uva 352 The Seasonal War
    switch语句
    java——基础知识
    我的lua学习2
    codeforces 431 D. Random Task 组合数学
    codeforces 285 D. Permutation Sum 状压 dfs打表
  • 原文地址:https://www.cnblogs.com/waw/p/2156710.html
Copyright © 2020-2023  润新知