//Widget.h#ifndef WIDGET_H#define WIDGET_H#include <QWidget>#include <QPainter>class Widget : public QWidget{ Q_OBJECTpublic: explicit Widget(QWidget *parent = 0); virtual void PaintEvent(QPaintEvent *event);signals:public slots:};#endif // WIDGET_H
//Widget.cpp#include "widget.h"#include <QPainter>Widget::Widget(QWidget *parent) : QWidget(parent){}void Widget::PaintEvent(QPaintEvent *event){ QPainter paint; paint.begin(this); QPen pen(Qt::red, 12, Qt::SolidLine); QBrush brush(Qt::red, Qt::SolidPattern); paint.setBrush(brush); paint.setPen(pen); paint.drawRect(3,14, 100, 50); paint.end();}
//main.cpp#include <QtGui/QApplication>#include <QTextCodec>#include <QPainter>#include "widget.h"#include <QPushButton>#include <QWidget>void main (int argc, char *argv[]){ QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows1251")); QApplication app(argc, argv); Widget w; w.show(); app.exec();}
void piped(GLfloat a, GLfloat b, GLfloat c){ glShadeModel(GL_FLAT); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glBegin(GL_QUAD_STRIP); glVertex3f(-a/2,-b/2,-c/2); glVertex3f(-a/2,-b/2, c/2); glVertex3f(-a/2, b/2,-c/2); glVertex3f(-a/2, b/2, c/2); glVertex3f( a/2, b/2,-c/2); glVertex3f( a/2, b/2, c/2); glVertex3f( a/2,-b/2,-c/2); glVertex3f( a/2,-b/2, c/2); glVertex3f(-a/2,-b/2,-c/2); glVertex3f(-a/2,-b/2, c/2); glEnd(); glBegin(GL_QUADS); glVertex3f(-a/2,-b/2, c/2); glVertex3f(-a/2, b/2, c/2); glVertex3f( a/2, b/2, c/2); glVertex3f( a/2,-b/2, c/2); glVertex3f(-a/2,-b/2,-c/2); glVertex3f(-a/2, b/2,-c/2); glVertex3f( a/2, b/2,-c/2); glVertex3f( a/2,-b/2,-c/2); glEnd();}
C++ (Qt)void graf::paintEvent ( QPaintEvent * event ){ QPainter paint; paint.begin(this); QPen pen(Qt::red, 12, Qt::SolidLine); QBrush brush(Qt::red, Qt::SolidPattern); paint.setBrush(brush); paint.setPen(pen); paint.drawRect(3,14, 100, 50); paint.end();} void graf::on_pushButton2_clicked(){ update();}