About box

Our next customization is to add an about box to our application. An about box is a dialog box that displays credits and revision information about the application. It may also include 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 click signal of that button we call a slot which will display the About box to the user. The code for the same 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 __main__ block before the myWindow.show() call. On execution, you will see a window with an added About button. On click of 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 by default at the side. The sample output is displayed as follows for your reference:

About box

There is one more function provided by the QMessage class that might 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 for displaying information about the platform 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.223.206.69