首先在Visual Studio 2005中建立一個QT專案,名為”painterpath”,
這裏使用PainterPath類別來進行繪圖的工作,
步驟:
在painterpath.h中新增下列一行
void paintEvent(QPaintEvent *event);
在painterpath.cpp新增一些程式碼
#include
#include
與
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| void painterpath::paintEvent(QPaintEvent *event) { QPainterPath path; path.addRect(20, 20, 60, 60);
path.moveTo(0, 0); path.cubicTo(99, 0, 50, 50, 99, 99); path.cubicTo(0, 99, 50, 50, 0, 0);
QPainter painter(this); painter.fillRect(0, 0, 100, 100, Qt::white); painter.setPen(QPen(QColor(79, 106, 25), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); painter.setBrush(QColor(122, 163, 39));
|
painter.drawPath(path);

- 先Bulild再偵錯,結果如下
