首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QWizard -后退按钮丢失

QWizard -后退按钮丢失
EN

Stack Overflow用户
提问于 2018-12-05 10:44:28
回答 1查看 414关注 0票数 0

我有一个QWizard,它以以下方式分支:

代码语言:javascript
复制
           ----- Page1 -----
         /                   \
StartPage  - Page2 - Page3 -  EndPage
         \                   /
           ----- Page4 -----

问题是,当通过StartPage -> page4 -> EndPage到达时,结束页只显示"back“按钮。否则,它只显示“完成”和“取消”。有没有人有类似的经历,是什么原因造成的?以下是它的设置方式:

代码语言:javascript
复制
QWizard wizard;
wizard.setPage(0, new StartPage(&wizard));
wizard.setPage(1, new Page1(&wizard));
wizard.setPage(2, new Page2(&wizard));
wizard.setPage(3, new Page3(&wizard));
wizard.setPage(4, new Page4(&wizard));
wizard.setPage(5, new EndPage(&wizard));

对于页面,nextId()被重新实现以返回正确的id。我搞不懂为什么通过不同的途径它的工作方式不同。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-05 13:23:06

没有人知道出了什么问题,因为您没有显示您的实现,所以我只提供一个代码来实现该方案,该代码显示:

wizard.h

代码语言:javascript
复制
#ifndef WIZARD_H
#define WIZARD_H

#include <QWizard>

class QButtonGroup;

class Wizard : public QWizard
{
    Q_OBJECT
public:
    enum { Start_Page,
           Page_1,
           Page_2, Page_3,
           Page_4,
           End_Page };
    Wizard(QWidget *parent=nullptr);
};

class StartPage: public QWizardPage
{
    Q_OBJECT
public:
    StartPage(QWidget *parent=nullptr);
    int nextId() const override;
private:
    QButtonGroup *group;
};

class Page1: public QWizardPage
{
    Q_OBJECT
public:
    Page1(QWidget *parent=nullptr);
    int nextId() const override;
};

class Page2: public QWizardPage
{
    Q_OBJECT
public:
    Page2(QWidget *parent=nullptr);
    int nextId() const override;
};

class Page3: public QWizardPage
{
    Q_OBJECT
public:
    Page3(QWidget *parent=nullptr);
    int nextId() const override;
};

class Page4: public QWizardPage
{
    Q_OBJECT
public:
    Page4(QWidget *parent=nullptr);
    int nextId() const override;
};

class EndPage: public QWizardPage
{
    Q_OBJECT
public:
    EndPage(QWidget *parent=nullptr);
    int nextId() const override;
};
#endif // WIZARD_H

wizard.cpp

代码语言:javascript
复制
#include "wizard.h"

#include <QButtonGroup>
#include <QLabel>
#include <QRadioButton>
#include <QVBoxLayout>

Wizard::Wizard(QWidget *parent):
    QWizard(parent)
{
    setPage(Start_Page, new StartPage);
    setPage(Page_1, new Page1);
    setPage(Page_2, new Page3);
    setPage(Page_3, new Page3);
    setPage(Page_4, new Page4);
    setPage(End_Page, new EndPage);
}

StartPage::StartPage(QWidget *parent):
    QWizardPage(parent)
{
    QVBoxLayout *lay = new QVBoxLayout(this);
    lay->addWidget(new QLabel("Start Page"));
    group = new QButtonGroup(this);
    for(const QString & text: {"Page1", "Page2", "Page4"}){
        QRadioButton *radio = new QRadioButton(text);
        lay->addWidget(radio);
        group->addButton(radio);
    }
    group->buttons().first()->setChecked(true);
    lay->addStretch();
}

int StartPage::nextId() const
{
    if(group->checkedButton()->text() == "Page1")
        return Wizard::Page_1;
    else if(group->checkedButton()->text() == "Page2")
        return Wizard::Page_2;
    return Wizard::Page_4;
}

Page1::Page1(QWidget *parent):
    QWizardPage(parent)
{
    QVBoxLayout *lay = new QVBoxLayout(this);
    lay->addWidget(new QLabel("Page1"));
}

int Page1::nextId() const
{
    return Wizard::End_Page;
}

Page2::Page2(QWidget *parent):
    QWizardPage(parent)
{
    QVBoxLayout *lay = new QVBoxLayout(this);
    lay->addWidget(new QLabel("Page2"));
}

int Page2::nextId() const
{
    return Wizard::Page_3;
}

Page3::Page3(QWidget *parent):
    QWizardPage(parent)
{
    QVBoxLayout *lay = new QVBoxLayout(this);
    lay->addWidget(new QLabel("Page3"));
}

int Page3::nextId() const
{
    return Wizard::End_Page;
}

Page4::Page4(QWidget *parent):
    QWizardPage(parent)
{
    QVBoxLayout *lay = new QVBoxLayout(this);
    lay->addWidget(new QLabel("Page4"));
}

int Page4::nextId() const
{
    return Wizard::End_Page;
}

EndPage::EndPage(QWidget *parent):
    QWizardPage(parent)
{
    QVBoxLayout *lay = new QVBoxLayout(this);
    lay->addWidget(new QLabel("End Page"));
}

int EndPage::nextId() const
{
    return -1;
}

main.cpp

代码语言:javascript
复制
#include "wizard.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Wizard w;
    w.show();
    return a.exec();
}

完整的示例可以找到here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53630483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档