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
Forum Updated to NodeBB v4.3 + New Features

QTBUG-54180 havn't been resolved in 5.9

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 1.4k 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
    #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