HELP Please !!! Bad Line Drawing when QGLWidget is used in a QGraphicsView

  • Hello,
    I am porting a CAD application to Qt. The legacy code draws all curves with line segments and I am using that code to draw into a QT scene. I use a QGraphicsView with QGraphicsScene and a QGLWidget as a viewport widget.

    This combination is working fine in most respects except for the bad quality of the non-Antialiased line drawing when using a QGLWidget. There are double pixel lines that appear at seemingly random places and ugly clumps of double pixel overlaps in various places and at various line slopes.

    I don't see these anomalies when using a standard widget. There are a few overshooting points but nothing too ugly.

    I have not seen this bad a line rasterization before so I am confused as to what is happening.
    Has anyone else experienced this problem?
    Is there a way to eliminate it or at least reduce it, settings or hinting perhaps?
    Is it a bug or am I doing something wrong?

    "Here is a link to several screen shots that show this.":
    EDIT: I added the files to build the test app to the link folder.

    The bad line images are drawn using the QGLWidget and the better line images are drawn using a normal QWidget.

    I am using Qt 5.2.1 on Windows 7 and Mac OS X 10.9.4 and I get the same result on both platforms.

    Below is the code I used to make the images. You can also fin the project files in the folder with the screen shots. Any suggestions as to how to eliminate these "bad" lines will be gratefully received.

    #ifndef DIALOG_H
    #define DIALOG_H

    #include <QDialog>

    namespace Ui {
    class Dialog;

    class Dialog : public QDialog

    explicit Dialog(QWidget *parent = 0);

    int getSides();
    bool getAA();

    Ui::Dialog *ui;

    #endif // DIALOG_H

    #ifndef MYWIDGET_H
    #define MYWIDGET_H

    #include <QWidget>
    #include <QGraphicsView>

    class MyWidget : public QGraphicsView

    int sides;
    bool useAA;

    MyWidget(int s,bool aa, QWidget *parent = 0);


    #endif // MYWIDGET_H

    #include "dialog.h"
    #include "ui_dialog.h"

    Dialog::Dialog(QWidget *parent) :
    ui(new Ui::Dialog)

    int Dialog::getSides()
    return ui->spinBox->value();

    bool Dialog::getAA()
    return ui->checkBox->isChecked();

    delete ui;

    #include <QtGui>
    #include <QGraphicsView>
    #include <QGraphicsScene>
    #include <QGLWidget>

    #include "mywidget.h"

    MyWidget::MyWidget(int s, bool aa, QWidget *parent)
    : QGraphicsView(parent)
    setWindowTitle("OpenGL Widget");
    // setRenderHint(QPainter::Qt4CompatiblePainting,true);
    QGraphicsScene *myscene = new QGraphicsScene();

    QGLWidget *myglwidget = new QGLWidget(QGLFormat(QGL::SampleBuffers));
    QPointF origin(sceneRect().width()/2.0,sceneRect().height()/2.0);
    sides = s;
    double radius=200.0;
    double angled = M_PI * 2.0 / (double)sides;
    double angle=0.0;
    for(int j=10; j<250; j+=10)
        radius = j;
        for(int i=0; i<sides; i++)
            double x1 = origin.x() + radius * cos(angle);
            double y1 = origin.y() + radius * sin(angle);
            angle += angled;
            double x2 = origin.x() + radius * cos(angle);
            double y2 = origin.y() + radius * sin(angle);


    #include <QApplication>

    #include "mywidget.h"
    #include "dialog.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);
    Dialog mydialog;
    int sides=4;
    bool useAA=false;

        sides = mydialog.getSides(&#41;;
        useAA = mydialog.getAA(&#41;;
    MyWidget mywidget(sides,useAA&#41;;
    return app.exec(&#41;;


  • Hello Again, No one has picked up on my post so I will appeal again.

    Does anyone have any ideas as to where this ugly line drawing is coming from?

    Am I doing something wrong?
    Is this normal?
    Is this a bug?

    Thanks again for a any ideas.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.