About... from the application menu.I\'m using Qt Designer to layout my m" />
开发者

Standard "About" dialog in Qt

开发者 https://www.devze.com 2023-02-21 11:59 出处:网络
What\'s the standard way to implement an \"About\" application dialog in 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 m

What's the standard way to implement an "About" application dialog in 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 wind开发者_运维技巧ow, but I don't need anything fancy. 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...


You can use QMessageBox::about for simple about dialogs, or write your own QDialog subclass if you need anything more special/fancy.


  1. Create a form. Right click on Project, Add New.., then select Qt in Files and Classes, select Qt Designer Form Class on right side and click choose..
  2. Select Dialog without Buttons and click next.
  3. Name it, for example "About".
  4. Open About.ui in designer and change this window as desired, i.e. add icon, text, buttons (maybe only OK button) and save it.
  5. In mainwindow.h add this object, i.e. About *about;
  6. In mainwinodw.cpp instantiate it, about = new About(this); If you put 0 instead of this, it will not be a "modal" window, so add this in parentheses.
  7. Go to Designer and in Action Editor right click on menu item and select Go to slot -> triggered.
  8. Write about->show(); in that slot.


In my program Wallch ( http://sourceforge.net/projects/wall-changer/ ), i have added a new qt designer form class.

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:

First set up the menus/actions (I did this inside the __init__ function of my QMainWindow subclass):

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:

@Slot()
def about(self):
    QMessageBox.about(self, 'title', 'text')
0

精彩评论

暂无评论...
验证码 换一张
取 消