An application icon

Source: Internet
Author: User

The application icon is a small image which are usually displayed in the top left corner of the titlebar. In the following example we'll show how we did it in PYQT4. We'll also introduce some new methods.

#!/usr/bin/python#-*-coding:utf-8-*-"" "Zetcode PyQt4 Tutorial This example shows an Iconin the titlebar of the window. Author:jan Bodnarwebsite:zetcode.com last Edited:october "" "Import sysfrom PyQt4 import Qtguiclass Example (QTGUI.QW Idget):        def __init__ (self):        super (Example, self). __init__ ()                Self.initui ()                    def initui (self):        self.setwindowtitle (' Icon ') self.setwindowicon (' Self.setgeometry ') (        qtgui.qicon (' web.png ') ))                    Self.show ()                def main ():        app = Qtgui.qapplication (SYS.ARGV)    ex = Example ()    sys.exit ( APP.EXEC_ ()) If __name__ = = ' __main__ ':    Main ()    

The previous example is coded in a procedural style. Python programming language supports both procedural and object oriented programming styles. Programming in PYQT4 means programming in OOP.

Class Example (Qtgui.qwidget):        def __init__ (self):        super (Example, self). __init__ ()        ...

The three most important things in object oriented programming is classes, data, and methods. Here we create a new class called Example . The Example class inherits from QtGui.QWidget class. This means, we call, Constructors:the first one for the class and the second one for the Example inherited class. The super() method returns the parent object of the Example class and we call its constructor. The __init__() method is a constructor method in Python.

The creation of the GUI is delegated to the initUI() method.

Self.setgeometry (Self.setwindowtitle (' Icon ') Self.setwindowicon (Qtgui.qicon (' web.png '))  

All three methods has been inherited from the QtGui.QWidget class. The setGeometry() does and the things. It locates the window on the screens and sets its size. The first and the parameters are the X and Y positions of the window. The third is the width and the fourth are the height of the window. In fact, it combines the and methods in one resize() move() method. The last method sets the application icon. To does this, we have created a QtGui.QIcon object. The receives the path to our icon to be QtGui.QIcon displayed.

def main ():        app = Qtgui.qapplication (SYS.ARGV)    ex = Example ()    sys.exit (APP.EXEC_ ()) If __name__ = = ' __main_ _ ':    Main ()   

The startup code has been placed in the main() method. This is a Python idiom.

Figure:icon

An application icon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.