Drawing text
We begin with drawing some Unicode text on the client area of a window.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we draw text in Russian azbuka. 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.text = u'\u041b\u0435\u0432 \u041d\u0438\u043a\u043e\u043b\u0430\
\u0435\u0432\u0438\u0447 \u0422\u043e\u043b\u0441\u0442\u043e\u0439: \n\
\u0410\u043d\u043d\u0430 \u041a\u0430\u0440\u0435\u043d\u0438\u043d\u0430' self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('Draw text')
self.show() def paintEvent(self, event): qp = QtGui.QPainter()
qp.begin(self)
self.drawText(event, qp)
qp.end() def drawText(self, event, qp): qp.setPen(QtGui.QColor(168, 34, 3))
qp.setFont(QtGui.QFont('Decorative', 10))
qp.drawText(event.rect(), QtCore.Qt.AlignCenter, self.text) def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
In our example, we draw some text in Azbuka. The text is vertically and horizontally aligned.
def paintEvent(self, event):
...
Drawing is done within the paint event.
qp = QtGui.QPainter()
qp.begin(self)
self.drawText(event, qp)
qp.end()
The QtGui.QPainter class is responsible for all the low-level painting. All the painting methods go between begin() and end() methods. The actual painting is delegated to the drawText() method.
qp.setPen(QtGui.QColor(168, 34, 3))
qp.setFont(QtGui.QFont('Decorative', 10))
Here we define a pen and a font which are used to draw the text.
qp.drawText(event.rect(), QtCore.Qt.AlignCenter, self.text)
The drawText() method draws text on the window. The rect() method of the paint event returns the rectangle that needs to be updated.
Figure: Drawing text
Drawing text的更多相关文章
- System.Drawing.Text.TextRenderingHint 的几种效果
; i < ; i++) { g5.TextRenderingHint = (System.Drawing.Text.TextRenderingHint)i; string txt; ; txt ...
- mono+jexus 验证码不显示:System.Drawing
System.ArgumentException The requested FontFamily could not be found [GDI+ status: FontFamilyNotFoun ...
- Cocoa Drawing
Graphics Contexts Graphics contexts are a fundamental part of the drawing infrastructure in Cocoa ap ...
- 类库探源——System.Drawing
一.System.Drawing 命名空间简述 System.Drawing 命名空间提供访问 GDI+ 的基本功能,更高级的功能在 System.Drawing.Drawing2D,System.D ...
- Quartz2D Text
[Quartz2D Text] Quartz 2D provides a limited, low-level interface for drawing text encoded in the Ma ...
- Java 绘制环形的文字 (Circle Text Demo)
1. [代码]CircleTextDemo.java import java.awt.*;import java.awt.event.*;import java.awt.geom.*; /** ...
- System.Drawing.Graphics.cs
ylbtech-System.Drawing.Graphics.cs 1.程序集 System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKey ...
- asp.net中ashx生成验证码代码放在Linux(centos)主机上访问时无法显示问题
最近有个项目加入了验证码功能,就从自己博客以前的代码中找到直接使用,直接访问验证码页面报错如下: 源代码:asp.net中使用一般处理程序生成验证码 Application Exception Sys ...
- ASP.NET图形验证码的生成
效果: 调用方法: int[] r = QAPI.VerifImage.RandomList();//取得随机数种子列 );//产生验证码字符 pictureBox1.Image = QAPI.Ver ...
随机推荐
- Codeforces Round #478 (Div. 2) ABCDE
A. Aramic script time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- [转]如何解决android模拟器慢的问题
分步阅读 在android开发的过程,发现android模拟器的速度不是一般的慢,那主要是因为android模拟器默认采用的是arm处理器造成的,这里主要提供两种方法: ① 利用intel虚拟硬件加速 ...
- uoj 41 【清华集训2014】矩阵变换 婚姻稳定问题
[清华集训2014]矩阵变换 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/41 Description 给出 ...
- C# 基于正则表达式的字符串验证
输入的字符串校验,是开发中经常遇到的问题,常用的办法是利用正则表达式进行判断.其特点是简洁有效. 1.正则表达基础知识 正则表达式的教程很多,这里两个基础教程: a.http://www.cnblog ...
- C#利用NPOI在同一个Excel文件中创建多个sheet
借用NPOI来实现,要在同一Excel文件中创建多个sheet,只需要在同一个workbook中创建多个sheet即可.要注意的是,sheet的名字一定不能重复.下面是实现的代码: private v ...
- JProfiler 5.1.4的使用方法
1. JProfiler运行环境配置 安装目录结构如下,子目录中显示了支持的操作系统: 在服务器和客户端都要安装JProfiler,并且要安装License,在分析工具客户端中进行安装.Windows ...
- linux下使用free命令查看实际内存占用(可用内存)
转:http://blog.is36.com/linux_free_command_for_memory/ linux下在终端环境下可以使用free命令看到系统实际使用内存的情况,一般用free -m ...
- linux防火墙查看、开启、关闭
查看 vi /etc/sysconfig/iptables 开启 service iptables stop 关闭 service iptables restart
- ASPNET CORE初探
ASP.NET Core 开发-中间件(Middleware) ASP.NET Core开发,开发并使用中间件(Middleware). 中间件是被组装成一个应用程序管道来处理请求和响应的软件组件 ...
- 记录memcache分布式策略及算法
摘要 http://wenku.baidu.com/link?url=eUmpWDGFiFguyQLxwmXwRYmbnW7Wm1Bo79dGoomSnmOPWDIA5-FFSTNRI7MBQq8QG ...