I am attached my code.
window.cpp
Window::Window()
{
GLWidget *openGL = new GLWidget(&helper, this);
// connect(timer, SIGNAL(timeout()), openGL, SLOT(animate()));
connect(timer, SIGNAL(timeout()), this, SLOT(calc()));
connect(this, SIGNAL(newData()), openGL, SLOT(animate()));
timer->start(250);
ellipse = 0.0;
setWindowTitle(tr("2D Painting on Native and OpenGL Widgets"));
}
//! [0]
void Window::calc()
{
// ...
emit newData();
}
Window::Window()
: QWidget()
{
GLWidget *openGL = new GLWidget(&helper, this);
QTimer *timer = new QTimer(this);
// connect(timer, SIGNAL(timeout()), openGL, SLOT(animate()));
connect(timer, SIGNAL(timeout()), this, SLOT(calc()));
connect(this, SIGNAL(newData()), openGL, SLOT(animate()));
timer->start(250);
ellipse = 0.0;
setWindowTitle(tr("2D Painting on Native and OpenGL Widgets"));
}
//! [0]
void Window::calc()
{
// ...
emit newData();
}
To copy to clipboard, switch view to plain text mode
GLWidget
::GLWidget(Helper
*helper,
QWidget *parent
){
elapsed = 0;
setFixedSize(600, 600);
setAutoFillBackground(false);
}
void GLWidget::animate()
{
elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
repaint();
}
{
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
image.setPixel(i,j,rand());//data[i][j]);
// qDebug() << image.pixel(i,j);
}
}
painter.begin(this);
painter.
setRenderHint(QPainter::Antialiasing);
painter.setViewport(0,0,600,600);
painter.scale(6,6);
painter.
fillRect(event
->rect
(),
QBrush(QColor(64,
32,
64)));
painter.drawImage(0,0,image);
painter.end();
}
GLWidget::GLWidget(Helper *helper, QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
elapsed = 0;
setFixedSize(600, 600);
setAutoFillBackground(false);
}
void GLWidget::animate()
{
elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
repaint();
}
void GLWidget::paintEvent(QPaintEvent *event)
{
QImage image(100, 100, QImage::Format_RGB16);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
image.setPixel(i,j,rand());//data[i][j]);
// qDebug() << image.pixel(i,j);
}
}
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setViewport(0,0,600,600);
painter.scale(6,6);
painter.fillRect(event->rect(), QBrush(QColor(64, 32, 64)));
painter.drawImage(0,0,image);
painter.end();
}
To copy to clipboard, switch view to plain text mode
Thanks in advance for the help.
QtBNL
Bookmarks