{
Q_OBJECT
public:
MRender(){}
signals:
void renderedPixmap
(const QImage &image
);
protected:
void run();
};
{
Q_OBJECT
public:
MCanvas(){}
public slots:
updatePixmap
(const QImage &image
);
protected:
private:
};
class MRender : public QThread
{
Q_OBJECT
public:
MRender(){}
signals:
void renderedPixmap(const QImage &image);
protected:
void run();
};
class MCanvas : public QWidget
{
Q_OBJECT
public:
MCanvas(){}
public slots:
updatePixmap(const QImage &image);
protected:
void paintEvent(QPaintEvent *e);
private:
QPixmap pixmap_;
};
To copy to clipboard, switch view to plain text mode
#include "main.h"
MRender::run()
{
while(1)
{
image.fill(0xFFFFFF);
painter.begin(&image);
painter.
drawText(textRect,Qt
::AlignCenter,
QString("Who are you?"));
painter.end();
emit renderedPixmap(image);
sleep(1);
}
}
MCanvas
::updatePixmap(const QImage &image
){
}
{
QPianter painter;
painter.begin(this);
painter.drawPixmap(0,0,pixmap_);
painter.end();
}
int main(int argc,char **argv);
{
MCanvas canvas=new MCanvas;
MRender render=new MRender;
QObject::connect(render,
SIGNAL(renderedPixmap
(const QImage &)),canvas,
SLOT(updatePixmap
(const QImage &)),Qt
::DirectConnection);
layout->addWidget(canvas);
widget->setLayout(layout);
widget->show();
app.exec();
delete widget;
return 0;
}
#include "main.h"
MRender::run()
{
while(1)
{
QPainter painter;
QImage image(400,400,QImage::Formage_RGB32);
image.fill(0xFFFFFF);
painter.begin(&image);
QRectF textRect(0,0,400,400);
painter.drawText(textRect,Qt::AlignCenter,QString("Who are you?"));
painter.end();
emit renderedPixmap(image);
sleep(1);
}
}
MCanvas::updatePixmap(const QImage &image)
{
pixmap_=QPixmap::fromImage(image);
}
MCanvas::paintEvent(QPaintEvent *e)
{
QPianter painter;
painter.begin(this);
painter.drawPixmap(0,0,pixmap_);
painter.end();
}
int main(int argc,char **argv);
{
QApplication app(argc,argv);
MCanvas canvas=new MCanvas;
MRender render=new MRender;
QObject::connect(render,SIGNAL(renderedPixmap(const QImage &)),canvas,SLOT(updatePixmap(const QImage &)),Qt::DirectConnection);
QWidget *widget=new QWidget;
QGridLayout *layout=new QGridLayout(widget);
layout->addWidget(canvas);
widget->setLayout(layout);
widget->show();
app.exec();
delete widget;
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks