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 ...
随机推荐
- 【四边形不等式】POJ1160[IOI2000]-Post Office
[题目大意] v个村庄p个邮局,邮局在村庄里,给出村庄的位置,求每个村庄到最近邮局距离之和的最小值. [思路] 四边形不等式,虽然我并不会证明:( dp[i][j]表示前i个村庄建j个邮局的最小值,w ...
- 置换python2.7.13的opcode遇到的一些坑
主要有两个坑 1.XXXSLICE相关的opcode #define SLICE #define SLICE_1 #define SLICE_2 #define SLICE_3 #define STO ...
- bzoj 3437: 小P的牧场 -- 斜率优化
3437: 小P的牧场 Time Limit: 10 Sec Memory Limit: 128 MB Description 小P在MC里有n个牧场,自西向东呈一字形排列(自西向东用1…n编号), ...
- Linux可以明文传输密码的工具sshpass
普通ssh只能手动输入密码,但是sshpass可以明文指定密码,但不建议使用,太不安全了.
- 用ldapsearch验证LDAP认证信息
企业里面各种各样的系统,堆积多了以后帐号数不胜数,比较好的解决方案之一是用LDAP.不过Microsoft的ActiveDirectory认证是否成功需要有命令来进行验证,可以通过ldapsearch ...
- 获取 ext grid 选中行 对象
在ext grid 中如何确定选中行?如何获取选中行数据? 其实很简单,用到了Ext.getCmp('id'),他可以获取到指定id的对象. grid 获取行对象: var row = Ext.get ...
- 使用Win2D在UWP程序中2D绘图(二)
绘制API 首先还是看一下前文的的示例: args.DrawingSession.DrawEllipse(155, 115, 80, 30, Colors.Black, 3); args.Dra ...
- OpenCV2马拉松第10圈——直方图反向投影(back project)
收入囊中 灰度图像的反向投影 彩色图像的反向投影 利用反向投影做object detect 葵花宝典 什么是反向投影?事实上没有那么高大上! 在上一篇博文学到,图像能够获得自己的灰度直方图. 反向投影 ...
- Install Linux Kernel 4.10 In CentOS and Ubuntu
https://www.ostechnix.com/install-linux-kernel-4-10-centos-ubuntu/
- Tomcat配置域名和虚拟文件夹
说明: 我在本机中添加域名模拟,假设是主机直接配置也能够使用.我用的tomcat是apache-tomcat-7.0.42 本地添加域名 本文介绍怎样通过改动tomcat的配置.实现通过IP地址或者域 ...