如何完全禁用或隐藏 QWizard 中的后退按钮?

发布于 2024-12-29 22:50:44 字数 40 浏览 4 评论 0原文

我想禁用或隐藏 QWizard 对话框中的后退按钮。我该怎么做呢?

I want to disable or hide Back button in QWizard dialog. How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过潦 2025-01-05 22:50:44

我查看了 Qt 的源代码,发现可以通过创建自定义按钮布局并在列表中省略“后退”按钮来隐藏“后退”按钮:

  QList<QWizard::WizardButton> button_layout;
  button_layout << QWizard::HelpButton << QWizard::Stretch <<
                   QWizard::NextButton << QWizard::CustomButton1 <<
                   QWizard::CancelButton;
  this->setButtonLayout(button_layout);

我希望这将为某人节省一些时间。

PS

AFAIU 为了避免使用 QTimer,需要修改 QWizard 源代码。最简单的方法是添加一个虚函数
虚拟无效按钮Updated();
并从 QWizard 的末尾调用它:
无效 QWizardPrivate::_q_updateButtonStates()
然后在您的 QWizard 子类中重新实现此 ButtonUpdated() 并禁用那里的“后退”按钮。

I've looked at Qt's sources and found out that it's possible to hide Back button by creating custom button layout and ommiting Back button in the list:

  QList<QWizard::WizardButton> button_layout;
  button_layout << QWizard::HelpButton << QWizard::Stretch <<
                   QWizard::NextButton << QWizard::CustomButton1 <<
                   QWizard::CancelButton;
  this->setButtonLayout(button_layout);

I hope this will save some time to somebody.

P.S.

AFAIU to avoid using QTimer it is needed to modify QWizard source code. The easies way will be to add a virtual function
virtual void buttonsUpdated();
and call it from the end of QWizard's:
void QWizardPrivate::_q_updateButtonStates()
Then reimplement this buttonsUpdated() in your QWizard sublass and disable Back button there.

并安 2025-01-05 22:50:44

另一种(可能更面向框架)方法是将 QWizardPage 设置为提交页面,该页面位于您希望禁用后退按钮的页面之前。只需在 QWizardPage 上调用 this.setCommitPage(true) ,下一页就不会启用后退按钮。

来自 QWizardPage 文档

void QWizardPage::setCommitPage(bool commitPage) 如果 commitPage 为 true,则将此页面设置为提交页面;否则,将其设置为
正常页面。提交页面是代表一个操作的页面,该操作
无法通过单击“后退”或“取消”来撤消。提交按钮取代
提交页面上的“下一步”按钮。单击此按钮只需调用
QWizard::next() 就像单击“下一步”一样。
直接从提交页面进入的页面禁用其后退按钮。另请参见 isCommitPage()。

如果您希望禁用所有后退按钮,您可以在每个页面上调用它。

An alternative (maybe more framework oriented) way would be to set the QWizardPage, which comes before the page you want the back button to be disabled in, to be a commit page. Just call this.setCommitPage(true) on a QWizardPage and the next page wont have its back button enabled.

from QWizardPage documentation

void QWizardPage::setCommitPage(bool commitPage) Sets this page to be a commit page if commitPage is true; otherwise, sets it to be a
normal page. A commit page is a page that represents an action which
cannot be undone by clicking Back or Cancel. A Commit button replaces
the Next button on a commit page. Clicking this button simply calls
QWizard::next() just like clicking Next does.
A page entered directly from a commit page has its Back button disabled. See also isCommitPage().

If you want all the back buttons to be disabled, you could just call it on every page.

黯然 2025-01-05 22:50:44

调用

QWizard::button(QWizard::BackButton).hide()

对我有用

QWizard::onCurrentIdChanged(int)

(在 PyQt4 中)。

这实际上在每个向导页面上再次隐藏了后退按钮,但它达到了预期的效果。

Calling

QWizard::button(QWizard::BackButton).hide()

in

QWizard::onCurrentIdChanged(int)

worked for me (in PyQt4).

This effectively hides the back button again on every wizard page, but it achieves the desired effect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文