QtGui.QBrush
The QtGui.QBrush
is an elementary graphics object. It is used to paint the background of graphics shapes, such as rectangles, ellipses, or polygons. A brush can be of three different types: a predefined brush, a gradient, or a texture pattern.
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- """
- ZetCode PyQt4 tutorial
- This example draws 9 rectangles in different
- brush styles.
- 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, 355, 280)
- self.setWindowTitle('Brushes')
- self.show()
- def paintEvent(self, e):
- qp = QtGui.QPainter()
- qp.begin(self)
- self.drawBrushes(qp)
- qp.end()
- def drawBrushes(self, qp):
- brush = QtGui.QBrush(QtCore.Qt.SolidPattern)
- qp.setBrush(brush)
- qp.drawRect(10, 15, 90, 60)
- brush.setStyle(QtCore.Qt.Dense1Pattern)
- qp.setBrush(brush)
- qp.drawRect(130, 15, 90, 60)
- brush.setStyle(QtCore.Qt.Dense2Pattern)
- qp.setBrush(brush)
- qp.drawRect(250, 15, 90, 60)
- brush.setStyle(QtCore.Qt.Dense3Pattern)
- qp.setBrush(brush)
- qp.drawRect(10, 105, 90, 60)
- brush.setStyle(QtCore.Qt.DiagCrossPattern)
- qp.setBrush(brush)
- qp.drawRect(10, 105, 90, 60)
- brush.setStyle(QtCore.Qt.Dense5Pattern)
- qp.setBrush(brush)
- qp.drawRect(130, 105, 90, 60)
- brush.setStyle(QtCore.Qt.Dense6Pattern)
- qp.setBrush(brush)
- qp.drawRect(250, 105, 90, 60)
- brush.setStyle(QtCore.Qt.HorPattern)
- qp.setBrush(brush)
- qp.drawRect(10, 195, 90, 60)
- brush.setStyle(QtCore.Qt.VerPattern)
- qp.setBrush(brush)
- qp.drawRect(130, 195, 90, 60)
- brush.setStyle(QtCore.Qt.BDiagPattern)
- qp.setBrush(brush)
- qp.drawRect(250, 195, 90, 60)
- def main():
- app = QtGui.QApplication(sys.argv)
- ex = Example()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
In our example, we draw nine different rectangles.
- brush = QtGui.QBrush(QtCore.Qt.SolidPattern)
- qp.setBrush(brush)
- qp.drawRect(10, 15, 90, 60)
We define a brush object. We set it to the painter object and draw the rectangle by calling thedrawRect()
method.
Figure: Brushes
QtGui.QBrush的更多相关文章
- 【转载】Pyqt 编写的俄罗斯方块
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function from __future__ ...
- Python win32api提取exe图标icon
转载地址: http://blog.csdn.net/gumanren/article/details/6129416 代码如下: # -*- coding: utf-8 -*- import sys ...
- Pyqt 窗体间传值
窗体间传值网上有好多方法,比如新建文件,先将子类窗体的数据传到文件中,父窗体读取文件. Signal&Slot机制进行传值 等等 在这里,我们就举个采用apply方法:Signal& ...
- Pyqt 打包资源文件
用打包工具将做好的Pyqt程序打包成exe后发现引用的资源图片都显示不了? 是否遇到了和我一样的问题呢.google之后找到了方法,一种方法是在程序中引用外部资源,另外一种方法是将资源文件转换为py文 ...
- Pyqt 设置 背景颜色和背景图片、 QPalette 调色板 与QPainter 画板区别 、 不规则图片
设置 背景颜色和背景图片 首先设置autoFillBackground属性为真然后定义一个QPalette对象设置QPalette对象的背景属性(颜色或图片)最后设置QWidget对象的Palette ...
- pyqt4制作透明无边框窗体
用PyQt做了一个无边框登陆窗口,效果如下: 下面是代码: # -*- coding: utf-8 -*- from PyQt4 import QtGui ,Qt ,QtCore image=QtGu ...
- pyqt记录内容(音乐播放器)
#这是UI文件 # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'AudioPlayerDia ...
- PyQt:个性化登录界面模仿QQ登录
写在前面 写了一个登录界面的demo,类似QQ的,写的自己喜欢的样式,贴一下代码,先上效果,如下 陈述 PyQt5+Python3.5.2 login.py是里登录的主界面loginWnd类,Head ...
- pyqt5_eric6_Qt desinger
麦子学院视频教程day1 1.创建pushbutton 绑定信号和槽 Ui_mainWindow.py 1 from PyQt5 import QtCore, QtGui, QtWidgets cla ...
随机推荐
- 解决关于stack溢出的问题
开发中经常遇到: 前端遇到Uncaught RangeError: Maximum call stack size exceeded错误 后台遇到java.lang.OutOfMemoryError: ...
- [COGS2427][HZOI 2016]seq
[COGS2427][HZOI 2016]seq 题目大意: 一个长度为\(n(n\le10^6)\)的序列,\(q(q\le10^6)\)次操作,每次将所有\(a\)变成\(b\),求最后的序列. ...
- 高斯消元法求解异或方程组: cojs.tk 539.//BZOJ 1770 牛棚的灯
高斯消元求解异或方程组: 比较不错的一篇文章:http://blog.sina.com.cn/s/blog_51cea4040100g7hl.html cojs.tk 539. 牛棚的灯 ★★☆ ...
- 基础知识(09) -- Spring 概述
Spring概述-------------------------------------------------------------------------主要内容: 1.Spring是什么 2 ...
- python开发_random
和java中的random()函数一样,在python中也有类似的模块random,即随机数 下面是我做的demo 运行效果: ==================================== ...
- 【原】Project configuration is not up-to-date with pom.xml
导入一个Maven项目之后发现有一个如下的错误: Project configuration is not up-to-date with pom.xml. Run project configura ...
- How to open a web site with the default web browser in a NEW window
http://delphi.about.com/cs/adptips2004/a/bltip0504_4.htm When using ShellExecute (as explained in th ...
- WICED -- Wireless Internet Connectivity for Embedded Devices
Broadcom's Wireless Internet Connectivity for Embedded Devices (WICED™) platform (pronounced "w ...
- .Net4.0并行库介绍——Task
Task和ThreadPool的功能类似,可以用来创建一些轻量级的并行任务.对于将一个任务放进线程池 ThreadPool.QueueUserWorkItem(A); 这段代码用Task来实现 ...
- h264 封装 RTMP中FLV数据的解析 rtmp协议简单解析以及用其发送h264的flv文件
一个完整的多媒体文件是由音频和视频2部分组成的.H264.Xvid等就是视频编码格式,MP3.AAC等就是音频编码格式.字幕文件只是其中附带部分. 把视频编码和音频编码打包成一个完整的多媒体文件,可以 ...