如何处理QDialogButtonBox RestoreDefaults按钮
在 Qt Designer 中,我创建了一个对话框,其中有一个 QDialogButtonBox,其中包含“确定”、“取消”和“恢复默认值”按钮。花了一段时间,但我弄清楚了如何在我的实现文件中设置信号/槽:
QPushButton* resetButton = m_ui.buttonBox->button(QDialogButtonBox::RestoreDefaults);
connect(resetButton, SIGNAL(clicked()), this, SLOT(resetDefaultsPressed()));
我的问题是:有没有办法在 QtDesigner 中设置信号/槽,就像使用“确定”和“取消”按钮一样?我一直无法找到名为 RestoreDefaults
或类似的信号...我的方法有效,但如果所有信号/槽设置都在 中,那就太好了。 uic 生成的.h
文件。
In Qt Designer I created a dialog box that has a QDialogButtonBox
with OK, Cancel, and "Restore Defaults" buttons in it. It took a while, but I figured out how to setup the signals/slots in my implementation file with:
QPushButton* resetButton = m_ui.buttonBox->button(QDialogButtonBox::RestoreDefaults);
connect(resetButton, SIGNAL(clicked()), this, SLOT(resetDefaultsPressed()));
My question is this: Is there a way to setup the signals/slots in QtDesigner like you can with the OK and Cancel buttons? I haven't been able to find a signal called RestoreDefaults
or similar... The method I have works, but it would be nice if all the signal/slot setup was together in the .h
file that uic generates.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Qt Designer 只能处理类中声明的信号。
但是您可以编写一个从
QDialogButtonBox
派生的新类,使用信号clicked
来接收哪个按钮角色被触发,并发出新信号。然后,您可以将
QDialogButtonBox
升级到设计器中的新类,并且您必须手动为每个 ui 文件添加信号(左键单击升级的小部件,然后“更改信号/ slot...”),或者编写一个设计器插件,让您的自定义类出现在设计器小部件列表中(请参阅其他回答了解详情)。Qt Designer can only handle the signals declared in the class.
But you can write a new class derived from
QDialogButtonBox
, use the signalclicked
to receive which button role has been triggered, and emit new signals.Then you can either promote your
QDialogButtonBox
to that new class in the designer and you'll have to manually add the signals for each ui file (with a left-click on your promoted widget then "Change signal/slots..."), or write a designer plugin to have your custom class(es) appear in the designer widget list (see that other answer for details).我通过添加
到我的
OptionsWindow.ui
部分来完成此操作,然后在代码中它是:作为插槽。
I've done it by adding
to my
OptionsWindow.ui
<connections>
section, and then in code it is:as a slot.