PDA

View Full Version : Cosmetic pen with opengl rendering



spepegiuqt
14th June 2010, 17:13
Hi all,
I try to set the cosmetic pen for QGraphicsPolygonItem but if I use the opengl render it doesn't work as I expect.
Here the code:



scene.setSceneRect(-0.0005,-0.0005,0.001,0.001);

QPen pen;
pen.setColor(QColor(Qt::red));
pen.setCosmetic(true);

QPolygonF polyF;
polyF << QPointF(0.0002,0.0002)
<< QPointF(0.0003,0.0002)
<< QPointF(0.0003,0.0003)
<< QPointF(0.0002,0.0003);

QGraphicsPolygonItem* polyItem = new QGraphicsPolygonItem(polyF);

polyItem->setPen(pen);

scene.addItem(polyItem);

ui->graphicsView->setBackgroundBrush(Qt::black);
ui->graphicsView->setCacheMode(QGraphicsView::CacheBackground);
ui->graphicsView->setRenderHint(QPainter::Antialiasing);
ui->graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
ui->graphicsView->setScene(&scene);


if I comment out the following code line it works fine.


ui->graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));


Thanks,
Giuseppe

JD2000
14th June 2010, 21:37
Detailed Description

The QGLWidget class is a widget for rendering OpenGL graphics.

QGLWidget provides functionality for displaying OpenGL graphics integrated into a Qt application. It is very simple to use. You inherit from it and use the subclass like any other QWidget, except that you have the choice between using QPainter and standard OpenGL rendering commands.

Note the inherit bit.