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.":https://app.box.com/BadQtLines
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.
dialog.h
@
#ifndef DIALOG_H
#define DIALOG_H#include <QDialog>
namespace Ui {
class Dialog;
}class Dialog : public QDialog
{
Q_OBJECTpublic:
explicit Dialog(QWidget *parent = 0);
~Dialog();int getSides(); bool getAA();
private:
Ui::Dialog *ui;
};
@mywidget.h
@
#endif // DIALOG_H#ifndef MYWIDGET_H
#define MYWIDGET_H#include <QWidget>
#include <QGraphicsView>class MyWidget : public QGraphicsView
{
Q_OBJECTint sides; bool useAA;
public:
MyWidget(int s,bool aa, QWidget *parent = 0);};
#endif // MYWIDGET_H
@dialog.cpp
@
#include "dialog.h"
#include "ui_dialog.h"Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->spinBox->setValue(4);
}int Dialog::getSides()
{
return ui->spinBox->value();
}bool Dialog::getAA()
{
return ui->checkBox->isChecked();
}Dialog::~Dialog()
{
delete ui;
}
@mywidget.cpp
@
#include <QtGui>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGLWidget>#include "mywidget.h"
MyWidget::MyWidget(int s, bool aa, QWidget *parent)
: QGraphicsView(parent)
{
setWindowTitle("OpenGL Widget");
useAA=aa;
setRenderHint(QPainter::Antialiasing,useAA);
//if(useAA)
// setRenderHint(QPainter::Qt4CompatiblePainting,true);
QGraphicsScene *myscene = new QGraphicsScene();
setScene(myscene);QGLWidget *myglwidget = new QGLWidget(QGLFormat(QGL::SampleBuffers)); this->setViewport(myglwidget); QPointF origin(sceneRect().width()/2.0,sceneRect().height()/2.0); myscene->addLine(origin.x()-250.0,origin.y()-250.0,origin.x()+250.0,origin.y()+250.0,QPen(QBrush(QColor(0,0,0)),0.0)); myscene->addLine(origin.x()-250.0,origin.y()+250.0,origin.x()+250.0,origin.y()-250.0,QPen(QBrush(QColor(0,0,0)),0.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); myscene->addLine(x1,y1,x2,y2,QPen(QBrush(QColor(0,0,0)),0.0)); } }
}
@main.cpp
@
#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;
mydialog.exec();if(mydialog.Accepted) { sides = mydialog.getSides(); useAA = mydialog.getAA(); } MyWidget mywidget(sides,useAA); mywidget.resize(500,500); mywidget.show(); return app.exec();
}
@ -
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.