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' ...
随机推荐
- android aapt 用法 -- ApkReader
aapt 是android assert packaging tool的缩写,具体如下: 1. 列出apk包的内容 aapt l[ist] [-v] [-a] file.{zip,jar,apk} - ...
- Tasker to answer incoming call by pressing power button
nowadays, the smartphone is getting bigger in size, eg. samsung galaxy note and note 2, sorta big in ...
- 关于Google Android平台的ClockworkMod Recovery恢复模式
lockworkMod Recovery,它也被称为Clockwork与CWM,它是装载Google Android操作系统设备的一个自定义的Recovery恢复模式,它可以使得相关Android设备 ...
- AWR--service statistics
近期发现一个奇怪的现象,数据库报告上看负载非常高.可是cpu和等待事件都非常低,不知道消耗的资源跑到哪里去了? Snap Id Snap Time Sessions Cursors/Session B ...
- linux常用命令集锦
linux 查看所有用户所在组 vi /etc/group 一个用户可以属于多个组,查看用户所属的组,groups + 用户名 linux 查找文件命令 find -name 文件名 在 ...
- tomcat 的缓存机制
事出做项目时一个jsp页面修改后一直没有读出来,后来仔细研究了下tomcat才发现 当请求jsp页面时,Tomcat会分派给JspServlet来处理,在jspServlet的方法 service() ...
- 如何中断正在执行IO的 Quartz 作业
Interrupt a Quartz job that doing IO 如果你想中断正在执行IO的 Quartz 作业,在你使用 InterruptibleChannel 时这是可行的.引用一下Or ...
- 《OpenStack部署实践》
<OpenStack部署实践> 基本信息 作者: 张子凡 丛书名: 图灵原创 出版社:人民邮电出版社 ISBN:9787115346797 上架时间:2014-2-27 出版日期:2014 ...
- @Java虚拟机之对象访问
建立对象是为了使用对象,我们的java程序需要通过栈上的reference数据来操作堆上的具体对象. 对象访问会涉及到Java栈.Java堆.方法区这三个内存区域. 如下面这句代码: Object o ...
- hdu 4548 美素数 超级大水题
美素数 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submis ...