An application icon

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

时间: 2024-10-19 19:54:50

An application icon的相关文章

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

(1)原因 一切都是iOS8捣的鬼.您如果把模拟器换成iOS7.1或者更早的,就不会有这个问题.而现在在iOS8中要实现badge.alert和sound等都需要用户同意才能,因为这些都算做Notification"通知",为了防止有些应用动不动给用户发送"通知"骚扰用户,所以在iOS8时,要"通知"必须要用户同意才行. (2)解决思路:我们判断一下,如果系统版本大于等于8.0的话,我们就在用户打开应用的时候弹出一个框框提示说我们要发送通知给你,

Attempting to badge the application icon but haven't received permission from the user to badge the

今天调试出现了这个错误提示"Attempting to badge the application icon but haven't received permission from the user to badge the application",代码里已经设置了ios8的处理,修改了半天,最后终于找到了错误原因是怎么造成有,是之前在手机设置里已经把通知给关闭了,所以才造成了这个错误提示的出现. Attempting to badge the application icon b

iOS Icon尺寸、iPhone Ratina 分辨率

高清晰度的iPhone和iPod touch(单位:像素) 启动影像 :640 x 960 APP图标:114 x 114 App Store商店:1024 x 1024 Spotlight搜索小图标: 58 x 58 文档图标: 44 x 58 Web Clip图标 :114 x 114 工具栏和导航栏图标 : 约40 x 40 标签栏的图标:约60 x 60 报刊杂志:最长的边缘1024像素(最小) iPhone和iPod touch(单位:像素) 启动影像 :320 x 480 APP图标

Android icon vs logo

Android 配置文件中有icon和logo两个属性.那这两个属性有什么区别呢? 清单文件中activity的icon属性介绍: android:icon An icon representing the activity. The icon is displayed to users when a representation of the activity is required on-screen. For example, icons for activities that initi

ios项目icon和default图片命名规则

一.应用图片标准iOS控件里的图片资源,苹果已经做了相应的升级,我们需要操心的是应用自己的图片资源.就像当初为了支持iPhone 4而制作的@2x高分辨率版本(译者:以下简称高分)图片一样,我们要为iPad应用中的图片制作对应的高分版本.我知道不少开发者很有预见性的早在iOS 5.0 SDK上就完成了这一步升级.可是我还是要强调一点,那就是之前 Michael Jurewitz (@Jury)在推上提到过的: — 如果想让你的高分图片显示在新iPad上,你必须用Xcode 4.3.1 连同iOS

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

最新的参考apple官网地址:https://developer.apple.com/library/ios/qa/qa1686/_index.html,网页下面有详细的使用方法(ios7以后的) 转载地址:http://www.cnblogs.com/rothwell/archive/2012/05/18/2507570.html 关于程序中的应用图标的大小尺寸,说的很详细,转载备用 一.应用图片标准iOS控件里的图片资源,苹果已经做了相应的升级,我们需要操心的是应用自己的图片资源.就像当初为

Starting the application on Mac does not work(拷贝platforms到不同的位置,才能解决问题)

In some rare cases it can happen that the application does not launch and there is no reaction after double clicking on the application icon, not even the splash screen appears. The following work-around might help in this case. Verify issue First pl

ios8设置application badge value

在ios8中,直接设置application badge value会出错 1 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count]; 曝出”Attempting to badge the application icon but haven't received permission from the user to badge the application“的错误. 原因是因为在ios8中,设置应用的

itop 各图标的超链接 ,portal 与 主界面 切换按钮

首页                 'app_icon_url' => array(                         'type' => 'string',                         'description' => 'Hyperlink to redirect the user when clicking on the application icon (in the main window, or login/logoff pages)',