QWidget::render(...)
Короче вот полный код из оригинала
/* ======================================================================
** MousePaint.h
** ======================================================================
**
*/
#ifndef _MousePaint_h_
#define _MousePaint_h_
#include <qwidget.h>
#include <qpoint.h>
#include <qpixmap.h>
// ======================================================================
class MousePaint : public QWidget {
Q_OBJECT
private:
QPoint m_pt;
QPixmap m_pix;
protected:
virtual void paintEvent (QPaintEvent* pe);
virtual void mousePressEvent(QMouseEvent* pe);
virtual void mouseMoveEvent (QMouseEvent* pe);
public:
MousePaint(QWidget* pwgt = 0);
};
#endif //_MousePaint_h_
/////////////////////////////////////////////////////////////////////////
/* ======================================================================
** MousePaint.cpp
** ======================================================================
**
*/
#include <QMouseEvent>
#include <qpainter.h>
#include "MousePaint.h"
// ----------------------------------------------------------------------
MousePaint::MousePaint(QWidget* pwgt/*= 0*/)
: QWidget(pwgt)
{
m_pix.scaled(width(), height());
m_pix.fill(Qt::white);
}
// ----------------------------------------------------------------------
/*virtual*/void MousePaint::paintEvent(QPaintEvent*)
{
::bitBlt(this, 0, 0, &m_pix);
}
// ----------------------------------------------------------------------
/*virtual*/void MousePaint::mousePressEvent(QMouseEvent* pe)
{
if (pe->button() & Qt::RightButton) {
m_pix.fill(Qt::white);
repaint();
}
else {
QPainter painter;
painter.begin(this);
painter.drawPoint(pe->pos());
m_pt = QPoint(pe->pos());
painter.end();
::bitBlt(&m_pix, 0, 0, this);
}
}
// ----------------------------------------------------------------------
/*virtual*/void MousePaint::mouseMoveEvent(QMouseEvent* pe)
{
QPainter painter;
painter.begin(this);
painter.drawLine(m_pt, pe->pos());
m_pt = QPoint(pe->pos());
painter.end();
::bitBlt(&m_pix, 0, 0, this);
}