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 ...
随机推荐
- [BZOJ4817][SDOI2017]树点涂色(LCT+DFS序线段树)
4817: [Sdoi2017]树点涂色 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 692 Solved: 408[Submit][Status ...
- 【原创】Eclipse导入Android项目报错解决
1.点击报错的项目--->右键--->Properties--->选择Android--->将Project Build Target选择其一勾上-->Is Librar ...
- HDU 3974 Assign the task 并查集/图论/线段树
Assign the task Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- 关闭Spring Boot的Jsckson的FAIL_ON_EMPTY_BEANS
说明:Spring Boot中默认使用了Jackson做JSON的解析. 解决方法: 1.通过注入Bean来实现 错误: org.springframework.http.converter.Http ...
- 使用CefSharp在.Net程序中嵌入Chrome浏览器(二)——参数设置
在实现了.Net程序中嵌入Chrome浏览器后,下一步的个性化操作就是加入一些设置了,在前面的文章中,我们可以看到在使用Chrome控件前,有如下一个操作: var setting = new Cef ...
- Dual transistor improves current-sense circuit
In multiple-output power supplies in which a single supply powers circuitry of vastly different curr ...
- linux 升级系统内核linux-4.10版本
http://blog.csdn.net/steven_liwen/article/details/68487241
- ArcGIS教程:编辑特征
摘要 通过合并.又一次编号和删除类特征来编辑和更新特征文件. 使用方法 · 编辑特征工具同意您通过下面全部操作或某一操作来改动现有特征文件: 合并一组特征类 又一次编号特征类 ID 删除不须要的特征 ...
- 自己动手写js分享插件 [支持https] (可以分享QQ空间,微信,新浪微博。。。)
由于百度分享,jiathis 等分享插件在https下均会报错,就萌生了自己动手写一个分享插件的念头,其实实现起来一点都不难,以下代码都已在https网站运行通过,特附上以下代码:还请各位看官不吝赐教 ...
- Integer IntegerCache源码
先看一段测试结果: /*public static void main(String[] args) { Integer a = 128, b = 128; Integer c = 127, d = ...