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
An application icon的更多相关文章
- Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest
情况是这样子的,导入一个比较老的项目(两年前),它依赖于一个 Libraray,已经先导入了 library,现在导入项目的时候出了错 (1) Android Studio 目前提供将 SDK包成 . ...
- Qt Setting Application Icon
Qt4 设置应用程序图标 将一个ico图标放在资源文件夹下; 然后建立txt,输入 IDI_ICON1 DISCARABLE "myico.ico"; 保存文件,将其后缀改为.rc ...
- iOS 点击Application icon加载推送通知Data
今天做APNS远程推送通知遇到了一个问题,就是手机接收到通知的时候,如果马上点击通知的 alert view时候,系统马上唤醒你的Application,通知或调用你的didReceiveLocalN ...
- 【iOS开发-71】解决方式:Attempting to badge the application icon but haven't received permission from the...
(1)原因 一切都是iOS8捣的鬼.您假设把模拟器换成iOS7.1或者更早的,就不会有这个问题.而如今在iOS8中要实现badge.alert和sound等都需要用户允许才干,由于这些都算做Notif ...
- Attempting to badge the application icon but haven't received permission from the user to badge the application错误解决办法
今天刚刚学习UIApplication对象,当我希望利用这个对象在我们的应用图标上显示个数字的时候,xcode报了这个错误: 解决办法 : - (IBAction)applicationClicke ...
- iOS Icon尺寸、iPhone Ratina 分辨率
高清晰度的iPhone和iPod touch(单位:像素) 启动影像 :640 x 960 APP图标:114 x 114 App Store商店:1024 x 1024 Spotlight搜索小图标 ...
- os项目icon和default 等相关图标命名规则和大小设置
最新的参考apple官网地址:https://developer.apple.com/library/ios/qa/qa1686/_index.html,网页下面有详细的使用方法(ios7以后的) 转 ...
- 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 ...
- 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' ...
随机推荐
- 在WPF中使用全局快捷键
今天写一个小程序中使用到了全局快捷键,找到了我之前写的文章在c#中使用全局快捷键翻了一下,发现它是WinForm版本的,而我现在大部分写WPF程序了,便将其翻译了为WPF版本的了. static cl ...
- Scramble String -- LeetCode
原题链接: http://oj.leetcode.com/problems/scramble-string/ 这道题看起来是比較复杂的,假设用brute force,每次做分割,然后递归求解,是一个 ...
- 十大开源ERP点评 献给深水区的中小企业和CIO们
原文地址:http://www.oschina.net/news/58437/top-10-erp-software 如今,企业资源规划(ERP)和客户关系管理(CRM)系统的必要性已经被各种组织和企 ...
- 高手写的“iOS 的多核编程和内存管理”
原文地址:http://anxonli.iteye.com/blog/1097777 多核运算 在iOS中concurrency编程的框架就是GCD(Grand Central Dispatch), ...
- .NET:如何实现 “热插拔”?
背景 如果某个“功能”需要动态更新?这种动态更新,可能是需求驱动的,也可能是为了修改 BUG,面对这种场景,如何实现“热插拔”呢?先解释一下“热插拔”:在系统运行过程动态替换某些功能,不用重启系统进程 ...
- 使用 UIFontWDCustomLoader 载入自定义字体
UIFontWDCustomLoader https://github.com/daktales/UIFontWDCustomLoader You can use UIFontWDCustomLoad ...
- springmvc最简单的搭建,初学者必看
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ...
- 最小二乘法least square
上研究生的时候接触的第一个Loss function就是least square.最近又研究了一下,做个总结吧. 定义看wiki就够了.公式如下 E(w)=12∑n=1N{y−xWT}2E(w)=12 ...
- VS2010+OpenCV2.4.3配置
VS2010+OpenCV2.4.3配置: 环境变量path: D:\openCV2.4.3\opencv\build\x86\vc10\bin 项目-属性-VC++目录:(vs2008中,工具- ...
- @JVM新一代的垃圾回收算法
垃圾回收的瓶颈 传统分代垃圾回收方式,已经在一定程度上把垃圾回收给应用带来的负担降到了最小,把应用的吞吐量推到了一个极限.但是他无法解决的一个问题,就是Full GC所带来的应用暂停.在一些对实时性要 ...