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的更多相关文章

  1. 【转载】Pyqt 编写的俄罗斯方块

    #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function from __future__ ...

  2. Python win32api提取exe图标icon

    转载地址: http://blog.csdn.net/gumanren/article/details/6129416 代码如下: # -*- coding: utf-8 -*- import sys ...

  3. Pyqt 窗体间传值

    窗体间传值网上有好多方法,比如新建文件,先将子类窗体的数据传到文件中,父窗体读取文件.  Signal&Slot机制进行传值 等等 在这里,我们就举个采用apply方法:Signal& ...

  4. Pyqt 打包资源文件

    用打包工具将做好的Pyqt程序打包成exe后发现引用的资源图片都显示不了? 是否遇到了和我一样的问题呢.google之后找到了方法,一种方法是在程序中引用外部资源,另外一种方法是将资源文件转换为py文 ...

  5. Pyqt 设置 背景颜色和背景图片、 QPalette 调色板 与QPainter 画板区别 、 不规则图片

    设置 背景颜色和背景图片 首先设置autoFillBackground属性为真然后定义一个QPalette对象设置QPalette对象的背景属性(颜色或图片)最后设置QWidget对象的Palette ...

  6. pyqt4制作透明无边框窗体

    用PyQt做了一个无边框登陆窗口,效果如下: 下面是代码: # -*- coding: utf-8 -*- from PyQt4 import QtGui ,Qt ,QtCore image=QtGu ...

  7. pyqt记录内容(音乐播放器)

    #这是UI文件 # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'AudioPlayerDia ...

  8. PyQt:个性化登录界面模仿QQ登录

    写在前面 写了一个登录界面的demo,类似QQ的,写的自己喜欢的样式,贴一下代码,先上效果,如下 陈述 PyQt5+Python3.5.2 login.py是里登录的主界面loginWnd类,Head ...

  9. pyqt5_eric6_Qt desinger

    麦子学院视频教程day1 1.创建pushbutton 绑定信号和槽 Ui_mainWindow.py 1 from PyQt5 import QtCore, QtGui, QtWidgets cla ...

随机推荐

  1. HNOI2012永无乡

    fhq treap+启发式合并,将小的合并到大的上面,复杂度NlogN. 最好的一点是通过dfs将一个子树内的元素转到另一个元素上. By:大奕哥 #include<bits/stdc++.h& ...

  2. 二叉树遍历-JAVA实现

    二叉树遍历分为前序.中序.后序递归和非递归遍历.还有层序遍历. //二叉树节点 public class BinaryTreeNode { private int data; private Bina ...

  3. Java容器-引用数据类型排序+TreeSet、TreeMap底层实现

    目录 1.冒泡排序的实现 2.比较接口(普通数据类型.引用数据类型) 普通数据类型:冒泡排序 引用数据类型:包装类(Integer.String.Character.Date) 自定义类型:实体类:i ...

  4. Ruby入门(1)——windows下Ruby开发环境搭建

    1.获得和安装Ruby1.1 获取Ruby    1) 从 http://www.ruby-lang.org/en/downloads/ 下载Source Code或者RubyInstaller    ...

  5. Current mirror drives multiple LEDs from a low supply voltage

    Driving LEDs at a regulated current from low supply voltages can be difficult because minimal overhe ...

  6. 利用DC/DC开关调节器延长DSP系统的电池寿命 - 动态电压调节

    http://www.analog.com/zh/content/dc-to-dc_switching_regulator_insights/fca.html 作者:Sridhar Gurram,Ol ...

  7. DC-DC converter Control techniques

    As shown in figure 3.4, PWM controller contains two main parts; voltage error-amplifier and voltage ...

  8. Spring JdbcTemplate batchUpdate() 实例

    在某些情况下,可能需要将一批记录插入到数据库中.如果你对每条记录调用一个插件的方法,SQL语句将被重复编译,造成系统缓慢进行. 在上述情况下,你可以使用 JdbcTemplate BATCHUPDAT ...

  9. 解决IIS 不能下载.exe.config文件的方法

    IIS允许下载".config"文件 Config文件是web的配置文件,默认是不允许下载的,就算在MIME中配置“application/octet-stream”,也是下载不了 ...

  10. HTTP Error 404.2 - Not Found The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server(转)

    今天公司的同事問我,為什麼同一支程式在自己的電腦OK,部署到Server上會出現下面的錯誤 我想,沒有錯啊~ 我在這台Server所部署的程式一向都是OK的 看了錯誤的Error page, 發現是I ...