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. QTBUG-54180 havn't been resolved in 5.9

QTBUG-54180 havn't been resolved in 5.9

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 1.7k Views 1 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.
  • H Offline
    H Offline
    Henry Li
    wrote on last edited by
    #1

    In QTBUG-54180 described a bug about "QPainter drawText() combined with setFont() very slow". The Link is https://bugreports.qt.io/browse/QTBUG-54180.
    I think this bug havn't been resolved. If somebody can call the bug reporter Chris, please ask him the solution with this bug for me.
    I use VS2015 and Qt5.9.0. When use QPainter drawText() combined with setFont(), I found it very slow at the first time after the widget new. The function of drawText() costs 300ms. Besides, I delete the widget, then new another one, and drawText() with setFont(). It costs longer and longer time.
    To resolve this problem. I test Qt5.9.6, Qt5.9.7, Qt5.9.0, Qt5.6.2, Qt5.6.3 and Qt5.6.0. But no one can do it as better as MFC.
    Qt5.6 is better then Qt5.9.
    Who can help me? Thanks very much!

    aha_1980A 1 Reply Last reply
    0
    • H Henry Li

      In QTBUG-54180 described a bug about "QPainter drawText() combined with setFont() very slow". The Link is https://bugreports.qt.io/browse/QTBUG-54180.
      I think this bug havn't been resolved. If somebody can call the bug reporter Chris, please ask him the solution with this bug for me.
      I use VS2015 and Qt5.9.0. When use QPainter drawText() combined with setFont(), I found it very slow at the first time after the widget new. The function of drawText() costs 300ms. Besides, I delete the widget, then new another one, and drawText() with setFont(). It costs longer and longer time.
      To resolve this problem. I test Qt5.9.6, Qt5.9.7, Qt5.9.0, Qt5.6.2, Qt5.6.3 and Qt5.6.0. But no one can do it as better as MFC.
      Qt5.6 is better then Qt5.9.
      Who can help me? Thanks very much!

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Henry-Li

      The fix for QTBUG-54180 is contained in 5.9 and all upward versions. So I think your problem is something else.

      Can you show us your code?

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • H Offline
        H Offline
        Henry Li
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • H Offline
          H Offline
          Henry Li
          wrote on last edited by
          #4

          just an example code.

          //// widget.h/////////////////////////
          #ifndef WIDGET_H
          #define WIDGET_H

          #include <QWidget>
          #include <QFont>
          #include <QPen>
          #include <QPaintEvent>

          namespace Ui {
          class Widget;
          }

          class Widget : public QWidget
          {
          Q_OBJECT

          public:
          explicit Widget(QWidget *parent = nullptr);
          ~Widget();

          private:
          QString m_s1;
          QString m_s2;
          QString m_s3;
          QString m_s4;

          QFont m_Font;
          QPen m_Pen;
          

          private:
          Ui::Widget *ui;

          protected:
          void resizeEvent(QResizeEvent* event);
          virtual void paintEvent(QPaintEvent* event);
          };

          #endif // WIDGET_H

          ///////////////////widget.cpp///////////////////////

          #include "widget.h"
          #include "ui_widget.h"
          #include <QtFontDatabaseSupport/QtFontDatabaseSupport>

          Widget::Widget(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::Widget)
          {
          ui->setupUi(this);
          QString fontFile = "C:/Windows/Fonts/msyh.ttf";
          int fontID = QFontDatabase::addApplicationFont(fontFile);
          QString msyh = QFontDatabase::applicationFontFamilies(fontID).at(0);
          m_Font = QFont(msyh);
          m_Pen.setColor(QColor(255,0,0));
          m_s1 = "test1";
          m_s2 = "test2";
          m_s3 = "test3";
          m_s4 = "test4";
          }

          Widget::~Widget()
          {
          delete ui;
          }

          void Widget::resizeEvent(QResizeEvent* event)
          {
          QWidget::resizeEvent(event);
          QRect rc = this->rect();
          int iFontSize = rc.width() * 0.01 + 10;
          m_Font.setPixelSize(iFontSize);
          update();
          }
          void Widget::paintEvent(QPaintEvent* event)
          {
          QPainter painter(this);
          painter.setPen(m_Pen);
          painter.setFont(m_Font);
          QRect painterRect = painter.window();
          QTime t1;
          t1.start();
          painter.drawText(painterRect, Qt::AlignLeft | Qt::AlignVCenter, m_s1);
          painter.drawText(painterRect, Qt::AlignRight | Qt::AlignVCenter, m_s2);
          painter.drawText(painterRect, Qt::AlignBottom | Qt::AlignHCenter, m_s3);
          painter.drawText(painterRect, Qt::AlignTop | Qt::AlignHCenter, m_s4);
          qDebug() << t1.elapsed();
          }

          ////////////////////main.cpp//////////////////////////////////////////
          #include "widget.h"
          #include <QApplication>

          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv);
          Widget w;
          w.show();

          return a.exec();
          

          }

          1 Reply Last reply
          1
          • H Offline
            H Offline
            Henry Li
            wrote on last edited by
            #5

            please help me

            JKSHJ 1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              Fact is that it is slow. You have following options.

              1. If the text what you are drawing is static(remains same always), then you can draw the text on the Pixmap and draw the pixmap in paintEvent(..). This way it will be one time performance issue.
              2. Using the GraphicsView & drawing the text may improve the performance
              3. If the bug fixed, you need to have that patch. It should work for you.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              H 1 Reply Last reply
              0
              • H Henry Li

                please help me

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                @Henry-Li said in QTBUG-54180 havn't been resolved in 5.9:

                please help me

                Please submit a report to https://bugreports.qt.io/.

                In your report, include your test code and benchmarks (How fast was it in Qt 5.6? How fast was it in Qt 5.11?)

                Note: The Qt developers will be more likely to investigate if you show that Qt 5.11 is slower than Qt 5.6.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                H 1 Reply Last reply
                1
                • dheerendraD dheerendra

                  Fact is that it is slow. You have following options.

                  1. If the text what you are drawing is static(remains same always), then you can draw the text on the Pixmap and draw the pixmap in paintEvent(..). This way it will be one time performance issue.
                  2. Using the GraphicsView & drawing the text may improve the performance
                  3. If the bug fixed, you need to have that patch. It should work for you.
                  H Offline
                  H Offline
                  Henry Li
                  wrote on last edited by
                  #8

                  @dheerendra Thanks very much. I will try the options. They are very helpful I thought.

                  1 Reply Last reply
                  0
                  • JKSHJ JKSH

                    @Henry-Li said in QTBUG-54180 havn't been resolved in 5.9:

                    please help me

                    Please submit a report to https://bugreports.qt.io/.

                    In your report, include your test code and benchmarks (How fast was it in Qt 5.6? How fast was it in Qt 5.11?)

                    Note: The Qt developers will be more likely to investigate if you show that Qt 5.11 is slower than Qt 5.6.

                    H Offline
                    H Offline
                    Henry Li
                    wrote on last edited by
                    #9

                    @JKSH Yes, I want to report it. But for now, I have to do my work first. And mybe later, I will submit the porblem with more test code.

                    1 Reply Last reply
                    0
                    • dheerendraD Offline
                      dheerendraD Offline
                      dheerendra
                      Qt Champions 2022
                      wrote on last edited by dheerendra
                      #10

                      @Henry-Li

                      What I have noticed is that drawText(..) for the first time is slow. After that it is very fast. As work-around, you can try like follows. Add one dummy method drawMe() like this. Call this method once before you call show() method. So now drawText(..) inside paintEvent(..) will be fast. It hardly takes anytime. So performance issue is only at startup. After that it is nothing/negligible.

                      void MyWidget::drawMe()
                      {
                          pix = QPixmap(400,400);
                          QPainter painter(&pix);
                          QTime t1;
                          t1.start();
                          QRect r2(100,100,100,100);
                          painter.drawText(r2, Qt::AlignRight, "pthinks.com");
                          qDebug() << Q_FUNC_INFO << "Time Taken to Draw " << t1.elapsed();
                      }
                      // === main.cpp ======
                      MyWidget w;
                      w.drawMe();
                      w.show();
                      

                      Dheerendra
                      @Community Service
                      Certified Qt Specialist
                      http://www.pthinks.com

                      H 1 Reply Last reply
                      3
                      • dheerendraD dheerendra

                        @Henry-Li

                        What I have noticed is that drawText(..) for the first time is slow. After that it is very fast. As work-around, you can try like follows. Add one dummy method drawMe() like this. Call this method once before you call show() method. So now drawText(..) inside paintEvent(..) will be fast. It hardly takes anytime. So performance issue is only at startup. After that it is nothing/negligible.

                        void MyWidget::drawMe()
                        {
                            pix = QPixmap(400,400);
                            QPainter painter(&pix);
                            QTime t1;
                            t1.start();
                            QRect r2(100,100,100,100);
                            painter.drawText(r2, Qt::AlignRight, "pthinks.com");
                            qDebug() << Q_FUNC_INFO << "Time Taken to Draw " << t1.elapsed();
                        }
                        // === main.cpp ======
                        MyWidget w;
                        w.drawMe();
                        w.show();
                        
                        H Offline
                        H Offline
                        Henry Li
                        wrote on last edited by
                        #11

                        @dheerendra
                        Thank you. Your solution is good. But don't resolved my problem absolutely. My project is complicated and high-performance request. I still hope Qt itself can do it better.
                        Thank you again.

                        aha_1980A 1 Reply Last reply
                        0
                        • H Henry Li

                          @dheerendra
                          Thank you. Your solution is good. But don't resolved my problem absolutely. My project is complicated and high-performance request. I still hope Qt itself can do it better.
                          Thank you again.

                          aha_1980A Offline
                          aha_1980A Offline
                          aha_1980
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi @Henry-L,

                          as said before, please comment at the bugreport if you want an improvement.

                          The discussion here will be forgotten in a couple of days.

                          Qt has to stay free or it will die.

                          1 Reply Last reply
                          2

                          • Login

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