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

bad performance with scaled QPainter and drawing QPainterPath

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.7.0
    • 4.5.2, 4.5.3, 4.6.0, 4.6.1, 4.6.2
    • GUI: Painting
    • None
    • 8d7046fbd798c6104eca6098b828c505ca32085c

    Description

      When scaling a graphics view the performance is very low for large scale values.
      The observation is based on the following examples:

      Graphics View example
      #include <QtGui/QApplication> 
      
      #include <QGraphicsView> 
      #include <QGraphicsScene> 
      #include <QVBoxLayout> 
      #include <QTime> 
      
      class MyGV : public QGraphicsView { 
      
      public: 
      MyGV(QWidget* parent=0) : QGraphicsView(parent), mDrawCnt(0) { mStartT.start(); } 
      
      protected: 
      void paintEvent(QPaintEvent* event) { 
      QGraphicsView::paintEvent(event); 
      
      /// trigger another repaint 
      viewport()->update(); 
      } 
      
      void drawForeground(QPainter* painter, const QRectF& rect) { 
      painter->setTransform(QTransform(),false); 
      painter->drawText(10,10,QString::number(++mDrawCnt *1000/mStartT.elapsed())); 
      } 
      private: 
      int mDrawCnt; 
      QTime mStartT; 
      }; 
      
      #include <QGradient> 
      int main(int argc, char *argv[]) 
      { 
      QApplication a(argc, argv); 
      
      QGraphicsScene* scene = new QGraphicsScene; 
      
      const QRectF testItemRect(-100,-100,200,200); 
      #if 0 /// performance issue doesn't happen with simple Rects 
      scene->addRect(testItemRect,QPen(Qt::red), Qt::green); 
      #else 
      const int EDGE = 10; 
      QPainterPath path; 
      path.moveTo (testItemRect.bottomLeft() - QPointF(0, EDGE)); 
      path.arcTo ( QRectF(testItemRect.topLeft(), 
      QSizeF( EDGE*2, EDGE*2)), 180, -90); 
      path.arcTo ( QRectF(testItemRect.topRight(), 
      QSizeF( -EDGE*2, EDGE*2)), 90, 90); 
      path.arcTo ( QRectF(testItemRect.bottomRight(), 
      QSizeF( -EDGE*2, -EDGE*2)), 180, -90); 
      path.arcTo ( QRectF(testItemRect.bottomLeft(), 
      QSizeF( EDGE*2, -EDGE*2)), 90, 90); 
      scene->addPath(path,QPen(Qt::red), Qt::green); 
      #endif 
      
      QWidget mainWidget; 
      mainWidget.resize(200,200); 
      QVBoxLayout* layout = new QVBoxLayout(&mainWidget); 
      
      MyGV* view = new MyGV; 
      QMatrix matrix = view->matrix(); 
      
      /// 10000 -> ~27 fps 
      /// 1000 -> ~85 fps 
      /// 100 -> ~1900 fps 
      /// 10 -> ~2200 fps 
      /// 1 -> ~2400 fps 
      /// 0.1 -> ~3000 fps // a lot of white space 
      const double scaleValue = 10000; 
      
      matrix.scale(scaleValue,scaleValue); 
      view->setMatrix(matrix); 
      view->setScene(scene); 
      layout->addWidget(view); 
      
      mainWidget.show(); 
      
      return a.exec(); 
      }
      

      Attachments

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

        Activity

          People

            rodal Samuel Rødal
            mpejcoch Martin Pejcoch (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes