The application icon is a small image which is usually displayed in the top left corner of the titlebar. In the following example we will show how we do it in PyQt4. We will also introduce some new methods.

#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows an icon
in the titlebar of the window. author: Jan Bodnar
website: zetcode.com
last edited: October 2011
""" import sys
from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Icon')
self.setWindowIcon(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 was 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 are classes, data, and methods. Here we create a new class called Example. The Example class inherits from QtGui.QWidget class. This means that we call two constructors: the first one for the Example class and the second one for the 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.

self.initUI()

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

self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Icon')
self.setWindowIcon(QtGui.QIcon('web.png'))

All three methods have been inherited from the QtGui.QWidget class. The setGeometry() does two things. It locates the window on the screen and sets its size. The first two parameters are the x and y positions of the window. The third is the width and the fourth is the height of the window. In fact, it combines the resize() and move() methods in one method. The last method sets the application icon. To do this, we have created a QtGui.QIcon object. The QtGui.QIcon receives the path to our icon to be 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的更多相关文章

  1. Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest

    情况是这样子的,导入一个比较老的项目(两年前),它依赖于一个 Libraray,已经先导入了 library,现在导入项目的时候出了错 (1) Android Studio 目前提供将 SDK包成 . ...

  2. Qt Setting Application Icon

    Qt4 设置应用程序图标 将一个ico图标放在资源文件夹下; 然后建立txt,输入 IDI_ICON1 DISCARABLE "myico.ico"; 保存文件,将其后缀改为.rc ...

  3. iOS 点击Application icon加载推送通知Data

    今天做APNS远程推送通知遇到了一个问题,就是手机接收到通知的时候,如果马上点击通知的 alert view时候,系统马上唤醒你的Application,通知或调用你的didReceiveLocalN ...

  4. 【iOS开发-71】解决方式:Attempting to badge the application icon but haven't received permission from the...

    (1)原因 一切都是iOS8捣的鬼.您假设把模拟器换成iOS7.1或者更早的,就不会有这个问题.而如今在iOS8中要实现badge.alert和sound等都需要用户允许才干,由于这些都算做Notif ...

  5. Attempting to badge the application icon but haven't received permission from the user to badge the application错误解决办法

    今天刚刚学习UIApplication对象,当我希望利用这个对象在我们的应用图标上显示个数字的时候,xcode报了这个错误:  解决办法 : - (IBAction)applicationClicke ...

  6. iOS Icon尺寸、iPhone Ratina 分辨率

    高清晰度的iPhone和iPod touch(单位:像素) 启动影像 :640 x 960 APP图标:114 x 114 App Store商店:1024 x 1024 Spotlight搜索小图标 ...

  7. os项目icon和default 等相关图标命名规则和大小设置

    最新的参考apple官网地址:https://developer.apple.com/library/ios/qa/qa1686/_index.html,网页下面有详细的使用方法(ios7以后的) 转 ...

  8. Starting the application on Mac does not work(拷贝platforms到不同的位置,才能解决问题),还可设置DYLD_PRINT_LIBRARIES=1 观察动态库

    In some rare cases it can happen that the application does not launch and there is no reaction after ...

  9. Error: No resource found that matches the given name (at 'icon' with value '@mipmap/Icon')

    问题: error: Error: No resource found that matches the given name (at 'icon' with value '@mipmap/Icon' ...

随机推荐

  1. linux下patch命令使用详解---linux打补丁命令

    http://blog.csdn.net/pashanhu6402/article/details/51849354 语 法:patch [-bceEflnNRstTuvZ][-B <备份字首字 ...

  2. DU 4609 3-idiots FFT

    题意还是比较好懂. 给出若干个木棍的长度,问这些木棍构成三角形的可能性. 那么公式很容易知道 就是这些木棍组成三角形的所有情况个数 除以 从n个木棍中取3个木棍的情况数量C(n, 3) 即可 但是很显 ...

  3. [android]ShareSDK——内容分享和短信验证

    前言 新版本号ShareSDK的分享和短信验证,按官网的文档,都须要加入一个<Activity></Activity>标签,而分享和短息验证的这个标签内容都一样.会冲突. 解决 ...

  4. 制作MACOSX10.10.3/10.9安装启动盘U盘的教程

    下载MACOSX 10.10.3/10.9镜像文件,下载地址http://www.chinamac.com/download/mac14032.html1.准备好你需要的大于等于6G以上的U盘或者移动 ...

  5. BTA 常问的 Java基础40道常见面试题及详细答案

    原文:http://www.ymq.io/2018/03/10/java/ 八种基本数据类型的大小,以及他们的封装类 引用数据类型 Switch能否用string做参数 equals与==的区别 自动 ...

  6. xcode找不到真机设备 - 转

    先确认证书是否正确 再确认Bundle Indentifier 是否与证书匹配 再确认Deployment Target 为:sdk从6.0改为4.3 如果xcode还无法识别iphone, Xcod ...

  7. iframe在ie和firefox中的高度兼容性问题解决

    1.问题描述: <iframe src="p_photo_cont_iframe.html" name="iframe" width="700& ...

  8. Java 8 中 HashMap 的性能提升

    HashMap是一个高效通用的数据结构,它在每一个Java程序中都随处可见.先来介绍些基础知识.你可能也知 道,HashMap使用key的hashCode()和equals()方法来将值划分到不同的桶 ...

  9. kafka-manager:kafak的管理界面的安装和使用

    下载打包 release下载:https://github.com/yahoo/kafka-manager/releases 源码位置:https://github.com/yahoo/kafka-m ...

  10. 容器list使用之erase(其他容器也通用)

    今天无论如何要写点东西,算是搞清楚了一点东西吧.有点小小的成就感. 之前在程序里面使用了list容器,其中用到了erase()函数,之前一直没出现问题,这两天突然莫名奇妙.花了点时间,搞清楚了eras ...