Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. No effect of Qt::NoPen in QPainter

No effect of Qt::NoPen in QPainter

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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

      beeckscheB 1 Reply Last reply
      0
      • mrjjM mrjj

        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

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • beeckscheB beecksche

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @beecksche

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

          beeckscheB 1 Reply Last reply
          0
          • mrjjM mrjj

            @beecksche

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

            beeckscheB Offline
            beeckscheB Offline
            beecksche
            wrote on last edited by
            #5

            @mrjj
            So i found the error:

            I have to disable antialiasing:

            painter.setRenderHint(QPainter::Antialiasing, false);
            
            mrjjM 1 Reply Last reply
            2
            • beeckscheB beecksche

              @mrjj
              So i found the error:

              I have to disable antialiasing:

              painter.setRenderHint(QPainter::Antialiasing, false);
              
              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @beecksche

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

              Please flag as Solved if possible.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved