-
Bug
-
Resolution: Done
-
P2: Important
-
4.6.3, 4.7.0
-
None
-
Windows, Qt SDK 2010.04 and Qt SDK 2010.05-rc1
Linux, Qt SDK 2010.02
-
89cbb165600de9a557a8a621dc41b93c2a7a2b52, 4035ec3e9ed5ef904dd6f22adaf5e9deb24e9455, 27fcfeba19b5984795fdb427be625bb83257d225, 128d0c2d64abec366cec22dfca493e6f5e03aa9d
Drawing a path to a QGLFramebufferObject does not produce the same results as when drawn to a QWidget (or directly to a QGLWidget). The example code below was put together from Qt documentation and examples.
main.cpp
#include <memory>
#include <QtCore>
#include <QtGui>
#include <QtOpenGL>
void paintPath(QPaintDevice *device)
{
QPainter painter(device);
painter.setRenderHint(QPainter::Antialiasing);
QPainterPath path;
path.addRect(20, 20, 60, 60);
path.moveTo(0, 0);
path.cubicTo(99, 0, 50, 50, 99, 99);
path.cubicTo(0, 99, 50, 50, 0, 0);
painter.fillRect(0, 0, 200, 200, Qt::white);
painter.setPen(QPen(QColor(79, 106, 25), 1, Qt::SolidLine,
Qt::FlatCap, Qt::MiterJoin));
painter.setBrush(QColor(122, 163, 39));
painter.drawPath(path);
painter.end();
}
class GLWidget : public QGLWidget
{
public:
GLWidget(QWidget *parent = 0) : QGLWidget(parent), fbo(0)
{
setFixedSize(200, 200);
}
protected:
void initializeGL()
{
fbo.reset(new QGLFramebufferObject(200, 200));
paintPath(fbo.get());
}
void resizeGL(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, w, h, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void paintEvent(QPaintEvent *)
{
QPainter painter(this);
drawTexture(QPoint(), fbo->texture());
}
private:
std::auto_ptr<QGLFramebufferObject> fbo;
};
class Widget : public QWidget
{
public:
Widget(QWidget *parent) : QWidget(parent)
{
setFixedSize(200, 200);
}
protected:
void paintEvent(QPaintEvent *)
{
paintPath(this);
}
};
class Window : public QWidget
{
public:
Window() : QWidget()
{
Widget *native = new Widget(this);
GLWidget *openGL = new GLWidget(this);
QLabel *nativeLabel = new QLabel(tr("Native"));
nativeLabel->setAlignment(Qt::AlignHCenter);
QLabel *openGLLabel = new QLabel(tr("OpenGL FBO"));
openGLLabel->setAlignment(Qt::AlignHCenter);
QGridLayout *layout = new QGridLayout;
layout->addWidget(native, 0, 0);
layout->addWidget(openGL, 0, 1);
layout->addWidget(nativeLabel, 1, 0);
layout->addWidget(openGLLabel, 1, 1);
setLayout(layout);
setWindowTitle(tr("Native and OpenGL Widgets"));
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window w;
w.show();
return app.exec();
}