Colours
A colour is an object representing a combination of Red, Green, and Blue (RGB) intensity values. Valid RGB values are in the range from 0 to 255. We can define a colour in various ways. The most common are RGB decimal values or hexadecimal values. We can also use an RGBA value which stands for Red, Green, Blue, and Alpha. Here we add some extra information regarding transparency. Alpha value of 255 defines full opacity, 0 is for full transparency, e.g. the colour is invisible.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example draws three rectangles in three
different colours. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 350, 100)
self.setWindowTitle('Colours')
self.show() def paintEvent(self, e): qp = QtGui.QPainter()
qp.begin(self)
self.drawRectangles(qp)
qp.end() def drawRectangles(self, qp): color = QtGui.QColor(0, 0, 0)
color.setNamedColor('#d4d4d4')
qp.setPen(color) qp.setBrush(QtGui.QColor(200, 0, 0))
qp.drawRect(10, 15, 90, 60) qp.setBrush(QtGui.QColor(255, 80, 0, 160))
qp.drawRect(130, 15, 90, 60) qp.setBrush(QtGui.QColor(25, 0, 90, 200))
qp.drawRect(250, 15, 90, 60) def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
In our example, we draw 3 coloured rectangles.
color = QtGui.QColor(0, 0, 0)
color.setNamedColor('#d4d4d4')
Here we define a colour using a hexadecimal notation.
qp.setBrush(QtGui.QColor(200, 0, 0))
qp.drawRect(10, 15, 90, 60)
Here we define a brush and draw a rectangle. A brush is an elementary graphics object which is used to draw the background of a shape. The drawRect() method accepts four parameters. The first two are x and y values on the axis. The third and fourth parameters are the width and height of the rectangle. The method draws the rectangle using the current pen and brush.
Figure: Colours
Colours的更多相关文章
- 在LaTeX中使用颜色 Using colours in LaTeX
Using colours in LaTeX There are several elements in LATEX whose colour can be changed to improve th ...
- Colours–颜色库,包含100种预定义的颜色和方法
简介 Colours–颜色库,包含各种100种预定义的颜色和方法,可以简化颜色相关的开发工作. 项目主页: Colours 最新示例: 点击下载 快速入门 安装 通过Cocoapods安装 pod ' ...
- CF848E Days of Floral Colours——DP+多项式求逆/分治NTT
官方题解:http://codeforces.com/blog/entry/54233 就是由简入繁 1.序列处理,只考虑一个半圆 2.环形处理(其实这个就是多了旋转同构) 然后基于分割线邻居的跨越与 ...
- Windows 8 Metro风格颜色表-Metro colours
http://huaban.com/pins/538986818
- [Tools] Using colours in a NodeJS terminal - make your output pop
Use can use colour and styles to make it easy to spot errors and group common functionality into blo ...
- CF848E-Days of Floral Colours【dp,分治NTT】
正题 题目链接:https://www.luogu.com.cn/problem/CF848E 题目大意 \(2n\)个花排成一个圆环,\(n\)种颜色每种两个,要求两个相同颜色之间最小距离为\(1, ...
- Codeforces 848E - Days of Floral Colours(分治 FFT)
Codeforces 题目传送门 & 洛谷题目传送门 神仙 D1E,一道货真价实的 *3400 %%%%%%%%%%%% 首先注意到一点,由于该图为中心对称图形,\(1\sim n\) 的染色 ...
- 使用R画地图数据
用R画地图数据 首先,从这里下载中国地图的GIS数据,这是一个压缩包,完全解压后包含三个文件(bou2_4p.dbf.bou2_4p.shp和bou2_4p.shx),将这三个文件解压到同一个目录下. ...
- Unity 最佳实践
转帖:http://www.glenstevens.ca/unity3d-best-practices/ 另外可以参考:http://devmag.org.za/2012/07/12/50-tips- ...
随机推荐
- POJ3071 Football 概率DP 简单
http://poj.org/problem?id=3071 题意:有2^n个队伍,给出每两个队伍之间的胜率,进行每轮淘汰数为队伍数/2的淘汰赛(每次比赛都是相邻两个队伍进行),问哪只队伍成为冠军概率 ...
- Codeforces 839E Mother of Dragons(极大团)
[题目链接] http://codeforces.com/contest/839/problem/E [题目大意] 现在有一些点,现在你有k的液体,随意分配给这些点, 当两个点有边相连的时候,他们能产 ...
- redisson实现基于业务的互斥锁
虽然数据库有锁的实现,但是有时候对于数据的操作更需要业务层控制. 这个解决的问题有次面试被问到过,当时不知道怎么解决,乱说一通,今天也算是有个解决方案了 项目中有个需求,就是订单需要经过一层一层的审核 ...
- [转]基础总结篇之一:Activity生命周期
子曰:溫故而知新,可以為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就完全掌握,那基本不大可能,所以我们需要经常回过头再仔细研读几遍,以领悟到作者的思 ...
- Maven安装详细图文教程
1.安装maven前需要先安装java,并设置JAVA_HOME环境变量.(详见jdk安装教程) 2. 将apache-maven-3.0.5-bin.zip放到d:\teamwork(自定义目录) ...
- OpenCV2马拉松第12圈——直方图比較
收入囊中 使用4种不同的方法进行直方图比較 葵花宝典 要比較两个直方图, 首先必需要选择一个衡量直方图相似度的对照标准.也就是先说明要在哪个方面做对照. 我们能够想出非常多办法,OpenCV採用了下面 ...
- win7 系统装SQLServer2000 成功
昨天在win7上装SQLServer数据库,写一下体会.首先,如果以前安装的话,要删除干净.我也找了半天的网络资料.1.把原来SQLServer的安装目录 C:\Program Files\Micro ...
- java获取指定日期之前或之后的时间
/** * 前/后?分钟 * * @param d * @param minute * @return */ public static Date rollMinute(Date d, int min ...
- 最好的 NMAP 扫描策略
# 适用所有大小网络最好的 nmap 扫描策略 # 主机发现,生成存活主机列表 $ nmap -sn -T4 -oG Discovery.gnmap 192.168.56.0/24 $ grep &q ...
- win7 64位搭建scrapy(转)
win7 64位系统依赖的scrapy文件链接:http://pan.baidu.com/s/1mgJS7BM 一个很好的python 64位包下载页面:http://www.lfd.uci.edu/ ...