Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-77356

QOpenGLWidget 2D painting with QPainter coordinate x error?

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P4: Low
    • Resolution: Unresolved
    • Affects Version/s: 5.12.3
    • Fix Version/s: None
    • Component/s: GUI: Painting
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      When draw 2D with QPainter  on QOpenGLWidget, the QPainter coordinate act as translate(-1,0). The x=0 position always invisible.

      Take 'Examples\Qt-x.x.x\opengl\2dpainting' for example:

      1, disable QPainter::Antialiasing

      void GLWidget::paintEvent(QPaintEvent *event)
      {
          QPainter painter;
          painter.begin(this);
          //painter.setRenderHint(QPainter::Antialiasing);
          helper->paint(&painter, event, elapsed);
          painter.end();
      }
      void Widget::paintEvent(QPaintEvent *event)
      {
          QPainter painter;
          painter.begin(this);
          //painter.setRenderHint(QPainter::Antialiasing);
          helper->paint(&painter, event, elapsed);
          painter.end();
      }
      

       

      2, Change Helper::Paint event:

      void Helper::paint(QPainter *painter, QPaintEvent *event, int elapsed)
      {
          painter->setPen(Qt::red);
          painter->fillRect(event->rect(), Qt::gray);
          painter->drawRect(event->rect());
      }

       

      Then you will get the result:

       

       

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              vgt Eirik Aavitsland
              Reporter:
              lding liu ding
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes