绘图事件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
void paintEvent(QPaintEvent *event);
private:
Ui::Widget *ui;
};
#endif
#include "widget.h"
#include "ui_widget.h"
#include <QPainter>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPen pen(QColor(255,0,0));
pen.setWidth(3);
pen.setStyle(Qt::DotLine);
painter.setPen(pen);
QBrush brush(Qt::green);
brush.setStyle(Qt::Dense7Pattern);
painter.setBrush(brush);
painter.drawLine(QPoint(0,0),QPoint(100,