About box

Our next customization to our application is to add the functionality to display an about box. An about box is a dialog box that displays credits and revision information about the application. It may also include the installed version and copyright information. The QMessageBox class provides a built-in function for this. It has the following signature:

PySide.QtGui.QMessageBox.about(parent, title, text)

The parent parameter takes any valid QWidget object. The title and text can be supplied with the Unicode parameter. The about box will have a single button labeled OK. To explain its working, we will now add a button named About, and on the click signal of this button, we call a slot which will display the About box to the user. The code for this is as follows:

    def setAboutButton(self):
        """ Function to set About Button
        """
        self.aboutButton = QPushButton("About", self)
        self.aboutButton.move(100, 100)
        self.aboutButton.clicked.connect(self.showAbout)

       def showAbout(self):
        """ Function to show About Box
        """
        QMessageBox.about(self.aboutButton, "About PySide",
               "PySide is a cross-platform tool for generating GUI Programs.")

Call this function from your initGUI block before the self.show() call. On execution, you will see a window with an added About button. On clicking this button, a separate dialog box is displayed with the heading and content text as given in the program. You can also note that the window also has the application icon displayed at the side by default. The sample output is displayed as follows for your reference:

About box

There is one more function that is provided by the QMessage class that may interest you. The aboutQt method is called, whose signature is given as follows:

PySide.QtGui.QMessageBox.aboutQt(parent[, title=""])

Calling this function will display a simple message box about Qt, with the given title and centered over parent. The message will display the version of the Qt that is currently used by the application. It is useful to display information about the platform that you are using in your program. As a learning exercise, try to implement this on your own and see what its output is.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.54.245