Pyqt 简明教程
PyQt - Drawing API
PyQt 中的所有 QWidget 类都是从 QPaintDevice 类派生的子类。 QPaintDevice 对可以通过 QPainter 绘图的二维空间进行抽象。画图设备的尺寸以从左上角开始的像素为单位进行测量。
All the QWidget classes in PyQt are sub classed from QPaintDevice class. A QPaintDevice is an abstraction of two dimensional space that can be drawn upon using a QPainter. Dimensions of paint device are measured in pixels starting from the top-left corner.
QPainter 类对窗口小部件和打印机等其他可画图设备执行低级绘图。通常,它在窗口小部件的绘制事件中使用。 QPaintEvent 每当窗口小部件的外观更新时就会发生。
QPainter class performs low level painting on widgets and other paintable devices such as printer. Normally, it is used in widget’s paint event. The QPaintEvent occurs whenever the widget’s appearance is updated.
通过调用 begin() 方法激活绘图器,而 end() 方法将其停用。在两者之间,使用下表中所列的适当方法绘制所需的图案。
The painter is activated by calling the begin() method, while the end() method deactivates it. In between, the desired pattern is painted by suitable methods as listed in the following table.
Sr.No. |
Methods & Description |
1 |
begin() Starts painting on the target device |
2 |
drawArc() Draws an arc between the starting and the end angle |
3 |
drawEllipse() Draws an ellipse inside a rectangle |
4 |
drawLine() Draws a line with endpoint coordinates specified |
5 |
drawPixmap() Extracts pixmap from the image file and displays it at the specified position |
6 |
drwaPolygon() Draws a polygon using an array of coordinates |
7 |
drawRect() Draws a rectangle starting at the top-left coordinate with the given width and height |
8 |
drawText() Displays the text at given coordinates |
9 |
fillRect() Fills the rectangle with the QColor parameter |
10 |
setBrush() Sets a brush style for painting |
11 |
setPen() Sets the color, size and style of pen to be used for drawing |