[英]Standard "About" dialog in Qt
What's the standard way to implement an "About" application dialog in Qt?在 Qt 中实现“关于”应用程序对话框的标准方法是什么? You know, the kind that pops up when you go Help > About... from the application menu.
您知道,当您从应用程序菜单中转到“帮助”>“关于...”时弹出的那种。 I'm using Qt Designer to layout my main window, but I don't need anything fancy.
我正在使用 Qt Designer 来布局我的主窗口,但我不需要任何花哨的东西。 It would be nice to do it in 2 lines of code instead of creating a new class or a new form in Qt Designer...
最好用 2 行代码来完成,而不是在 Qt Designer 中创建一个新类或一个新表单......
您可以将QMessageBox::about用于简单的 about 对话框,或者如果您需要更特别/更花哨的内容,则可以编写自己的 QDialog 子类。
About *about;
About *about;
about = new About(this);
about = new About(this);
If you put 0
instead of this
, it will not be a "modal" window, so add this
in parentheses.0
而不是this
,它不会是一个“模态”窗口,所以在括号中添加this
。about->show();
about->show();
in that slot.In my program Wallch ( http://sourceforge.net/projects/wall-changer/ ), i have added a new qt designer form class.在我的程序 Wallch ( http://sourceforge.net/projects/wall-changer/ ) 中,我添加了一个新的 qt 设计器表单类。
It works just fine!它工作得很好!
( I referred the name of my application so if you want to check the project , not because it is my app ) (我提到了我的应用程序的名称,所以如果您想检查该项目,而不是因为它是我的应用程序)
Here's how I did it with Python/PySide2:这是我使用 Python/PySide2 的方法:
First set up the menus/actions (I did this inside the __init__
function of my QMainWindow subclass):首先设置菜单/操作(我在QMainWindow子类的
__init__
函数中执行此操作):
menu = self.menuBar().addMenu('&Help')
about_action = QAction('&About', self)
about_action.triggered.connect(self.about)
menu.addAction(about_action)
Then create a new slot to call QMessageBox.about :然后创建一个新槽来调用QMessageBox.about :
@Slot()
def about(self):
QMessageBox.about(self, 'title', 'text')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.