#ifndef APPWINDOW_H#define APPWINDOW_H#include <QWidget>namespace Ui{ class appwindow;}class appwindow : public QWidget{ Q_OBJECTpublic: appwindow(QWidget *parent = 0); ~appwindow();public slots: void startPaint();protected: void changeEvent(QEvent *e); void paintEvent(QEvent* e);private: Ui::appwindow *ui;};#endif // APPWINDOW_H
#include "appwindow.h"#include "ui_appwindow.h"#include <QPainter>appwindow::appwindow(QWidget *parent) : QWidget(parent), ui(new Ui::appwindow){ ui->setupUi(this); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(startPaint()));}appwindow::~appwindow(){ delete ui;}void appwindow::changeEvent(QEvent *e){ QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; }}void appwindow::startPaint(){ update();}void appwindow::paintEvent(QEvent* e){ QPainter painter(this); QBrush brush(Qt::red, Qt::SolidPattern); painter.setBrush(brush); painter.drawLine(10,10,-100,100);}