QPainter 类
- drawLine(): 此方法用于在两组x和y坐标之间绘制线
- drawlpoints(): 此方法用于在通过提供的x和y坐标指定的位置绘制点
- drawRect(): 此方法用于在两组x和y坐标之间绘制矩形
- drawArc(): 此方法用于从指定的中心位置、在两个指定角度之间以及使用指定的半径绘制圆弧
- drawText(): 此方法用于以指定的字体样式、颜色和大小绘制文本
实例
- 创建基于Dialog without Buttons模板窗口
- 添加两个Label部件,其text为This app will display x,y coordinates where mouse is moved on
- 保存为demoMousetrack.ui
- 使用pyuic生成demoMousetrack.py
- 创建callMouseTrack.py
import sys
from PyQt5.QtWidgets import QDialog,QApplication
from cookbook_200505.demoMousetrack import *
class MyForm(QDialog):
def __init__(self):
super().__init__()
self.ui=Ui_Dialog()
self.setMouseTracking(True)
self.ui.setupUi(self)
self.show()
def mousePressEvent(self, event):
x=event.x()
y=event.y()
text="x: {0},y: {1}".format(x,y)
self.ui.label.setText(text)
if __name__=="__main__":
app=QApplication(sys.argv)
w=MyForm()
w.show()
sys.exit(app.exec())