Antialiasing does not work with QGraphicsView



  • I have a simple application using Qt 5.0.1, it looks like:

    @

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    m_Settings = new QSettings();

    // Create the tab widget to hold all the editable documents in the center
    

    /*
    setTabPosition( Qt::AllDockWidgetAreas, QTabWidget::North );

    // Recent file action
    for (int i = 0; i < MaxRecentFiles; ++i) {
    m_RecentFileActions[i] = new QAction(this);
    m_RecentFileActions[i]->setVisible(false);
    connect(m_RecentFileActions[i], SIGNAL(triggered()),
    this, SLOT(openRecentFile()));
    }

    // Recent file menu
    QMenu fileMenu = ui->menuFile;
    m_SeparatorAction = fileMenu->addSeparator();
    for (int i = 0; i < MaxRecentFiles; ++i)
    fileMenu->addAction(m_RecentFileActions[i]);
    updateRecentFileActions();
    /
    QGraphicsView
    view = new QGraphicsView( this );
    view->setRenderHint( QPainter::HighQualityAntialiasing, true );
    this->setCentralWidget( view );
    view->setScene( new QGraphicsScene() );
    QGraphicsScene
    theScene( view->scene() );
    theScene->setSceneRect( -200, -200, 400, 400 );
    QGraphicsLineItem* newItem = new QGraphicsLineItem();
    theScene->addItem( newItem );
    newItem->setLine( -50, -50, 30, 50 );
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    The line renders extremely ugly and aliased. Why is this?

    Chris



  • This would have fixed it:

    @
    view->setRenderHints( QPainter::Antialiasing | QPainter::HighQualityAntialiasing );
    @

    It appears that asking for high quality antialiasing doesn't imply that you want antialiasing which is kind of odd but it works and is really nice now.


Log in to reply
 

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