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- ...
随机推荐
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- BZOJ 1040 ZJOI 2008 骑士 树形DP
题意: 有一些战士,他们有战斗力和讨厌的人,选择一些战士,使他们互不讨厌,且战斗力最大,范围1e6 分析: 把战士看作点,讨厌的关系看作一条边,连出来的是一个基环树森林. 对于一棵基环树,我们找出环, ...
- 1、Redis简介、安装和基础入门
-------------------------------------------------------- 主要内容包括: 1.Redis简介 2.Redis安装.启动.停止 3.Redis基础 ...
- 设计模式 -- 桥接模式(Bridge)
写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------主要内容包括: 初始桥接模式 ...
- js——引用类型和基本类型
js中的数据类型有以下几种: 基本类型:Number Boolean String undefined null Symbol 引用类型:Object(Array, Function, Date ...
- FreeRTOS API
Task Creation xTaskCreate vTaskDelete Task Control vTaskDelay vTaskDelayUntil uxTaskPriorityGet vTas ...
- android DrawerLayout 侧边栏实现
现在实现侧边栏比较简单了,官方提供的DrawerLayout可以很方便实现. 主要实现方法是:用DrawerLayout 作为界面根控件.在DrawerLayout里面第一个View为当前界面主内容: ...
- sessionid与cookie
转自:http://smiky.iteye.com/blog/649164 发现自己真的是很笨,过去一直用jsp,从来不用怕心用户信息放在session里面会找不到,现在不用jsp,前台全用html, ...
- UIBezierPath的使用(持续更新)
UIBezierPath的使用 1. 使用UIBezierPath绘制多边形 // 获取path UIBezierPath *aPath = [UIBezierPath bezierPath]; // ...
- 网页采集(通过HtmlAgilityPack+XPath)
有HtmlAgilityPack这个类库可以更方便地对HTML内容进行分析和提取.因此今天特别学习和实践了一下HtmlAgilityPack和XPath,并作下笔记. 1.下载HtmlAgilityP ...