No effect of Qt::NoPen in QPainter



  • Hi,
    i want to disable the pen in my paintEvent function.

    void PaintWidget::paintEvent(QPaintEvent *event)
    {
        QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.translate(width() / 2.0, height() / 2.0);
        painter.setPen(Qt::NoPen);
    
        for (auto poly : m_poliygons)
        {
            painter.setBrush(QBrush(poly .color()));
            painter.drawPolygon(poly.polygon());
        }
    }
    

    But the outlines of the polygons are still painted.

    Can someone help?


  • Qt Champions 2016

    Hi
    Works in Qt 5.7 on win 10.
    0_1486380294384_upload-07f5d838-919e-4c29-b703-ab9449361fc4 image url)

    void MainWindow::on_pushButton_2_released()
    {
    
        int h = ui->label->height();
        int w = ui->label->width();
    
        QPixmap pix(w, h);
        QPainter painter(&pix);
        pix.fill( Qt::white );
        QPolygon poly;
    
           poly << QPoint(0, 85) << QPoint(75, 75)
                << QPoint(100, 10) << QPoint(125, 75)
                << QPoint(200, 85) << QPoint(150, 125)
                << QPoint(160, 190) << QPoint(100, 150)
                << QPoint(40, 190) << QPoint(50, 125)\
                << QPoint(0, 85);
    
           //QPen pen(Qt::red, 3, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin);
           painter.setPen(Qt::NoPen);
           painter.setBrush(QBrush(Qt::HorPattern));
           painter.drawPolygon(poly);
    
           ui->label->setPixmap(pix);
    
    }
    
    

    with pen..
    0_1486380534335_upload-089bc1a3-3d64-4bd7-a170-6b9d72ce9161



  • @mrjj
    strange,
    i'm using the new Qt 5.8.0 MSVC2013, but i don't think that's the reason.


  • Qt Champions 2016

    @beecksche

    well try my code and see.
    If still Pen it might be bug :)



  • @mrjj
    So i found the error:

    I have to disable antialiasing:

    painter.setRenderHint(QPainter::Antialiasing, false);
    

  • Qt Champions 2016

    @beecksche

    ahahah :)
    so it was not a real pen at all.
    Good catch.

    Please flag as Solved if possible.


Log in to reply
 

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