QWizard - 后退按钮丢失
QWizard - back button missing
我有一个 QWizard,它按以下方式分支:
----- Page1 -----
/ \
StartPage - Page2 - Page3 - EndPage
\ /
----- Page4 -----
问题是,当通过 StartPage -> page4 -> EndPage 到达结束页面时,它只显示 "back" 按钮。否则它只显示 "finish" 和 "cancel"。有没有人有类似的经历,这可能是什么原因造成的?设置方法如下:
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() 被重新实现为 return 正确的 ID。我很困惑为什么它通过不同的路径工作不同。
没有人知道哪里出了问题,因为你没有展示你的实现,所以我将只提供一个代码来实现显示的方案:
wizard.h
#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
#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
#include "wizard.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Wizard w;
w.show();
return a.exec();
}
可以找到完整的示例 here。
我有一个 QWizard,它按以下方式分支:
----- Page1 -----
/ \
StartPage - Page2 - Page3 - EndPage
\ /
----- Page4 -----
问题是,当通过 StartPage -> page4 -> EndPage 到达结束页面时,它只显示 "back" 按钮。否则它只显示 "finish" 和 "cancel"。有没有人有类似的经历,这可能是什么原因造成的?设置方法如下:
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() 被重新实现为 return 正确的 ID。我很困惑为什么它通过不同的路径工作不同。
没有人知道哪里出了问题,因为你没有展示你的实现,所以我将只提供一个代码来实现显示的方案:
wizard.h
#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
#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
#include "wizard.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Wizard w;
w.show();
return a.exec();
}
可以找到完整的示例 here。