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. QWidget - the drawn image is erased
Qt 6.11 is out! See what's new in the release blog

QWidget - the drawn image is erased

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.3k 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.
  • M Offline
    M Offline
    mihail
    wrote on last edited by mihail
    #1

    Hi, everybody!

    Host OS: Linux x2004d 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
    Target Hardware: IMX8 Toradex Ixora V1.2A
    Target OS: Linux apalis-imx8-06543230 5.4.154-5.5.0+git.c65f1622951c #1 SMP PREEMPT Mon Jan 3 15:58:01 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
    KIT(SDK-Toolchain):
    /opt/tdx-xwayland-rt/5.5.0/sysroots/x86_64-tdxsdk-linux/usr/bin/qmake
    /opt/tdx-xwayland-rt/5.5.0/sysroots/x86_64-tdxsdk-linux/usr/bin/aarch64-tdx-linux/aarch64-tdx-linux-g++
    Example: /home/mihail/Qt/Examples/Qt-5.14.2/widgets/painting/gradients/

    I changed:

    ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent)
        : QWidget(parent), m_shade_type(type), m_alpha_gradient(QLinearGradient(0, 0, 0, 0))
    {
        ...
        setAttribute(Qt::WA_OpaquePaintEvent, true);  // Should not erase the previous one !
        QTimer *timer = new QTimer();
        connect(timer, &QTimer::timeout, this, &ShadeWidget::timerWork);
        timer->start(100);
    }
    void ShadeWidget::timerWork()
    {
        update();
    }
    void ShadeWidget::paintEvent(QPaintEvent *)
    {
        QPainter p(this);
        static int i = 0;
        if(i > width()) i = 0;
        p.setPen(Qt::red);
        p.drawLine(i, 0, i, height() - 1);  // draw the added line by timer
        i++;
    }
    

    Problem: Old drawn lines are erased! Why? How to fix it?
    Please help.

    jsulmJ Christian EhrlicherC 2 Replies Last reply
    0
    • M mihail

      Hi, everybody!

      Host OS: Linux x2004d 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
      Target Hardware: IMX8 Toradex Ixora V1.2A
      Target OS: Linux apalis-imx8-06543230 5.4.154-5.5.0+git.c65f1622951c #1 SMP PREEMPT Mon Jan 3 15:58:01 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
      KIT(SDK-Toolchain):
      /opt/tdx-xwayland-rt/5.5.0/sysroots/x86_64-tdxsdk-linux/usr/bin/qmake
      /opt/tdx-xwayland-rt/5.5.0/sysroots/x86_64-tdxsdk-linux/usr/bin/aarch64-tdx-linux/aarch64-tdx-linux-g++
      Example: /home/mihail/Qt/Examples/Qt-5.14.2/widgets/painting/gradients/

      I changed:

      ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent)
          : QWidget(parent), m_shade_type(type), m_alpha_gradient(QLinearGradient(0, 0, 0, 0))
      {
          ...
          setAttribute(Qt::WA_OpaquePaintEvent, true);  // Should not erase the previous one !
          QTimer *timer = new QTimer();
          connect(timer, &QTimer::timeout, this, &ShadeWidget::timerWork);
          timer->start(100);
      }
      void ShadeWidget::timerWork()
      {
          update();
      }
      void ShadeWidget::paintEvent(QPaintEvent *)
      {
          QPainter p(this);
          static int i = 0;
          if(i > width()) i = 0;
          p.setPen(Qt::red);
          p.drawLine(i, 0, i, height() - 1);  // draw the added line by timer
          i++;
      }
      

      Problem: Old drawn lines are erased! Why? How to fix it?
      Please help.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mihail said in QWidget - the drawn image is erased:

      How to fix it?

      Draw all lines including old lines. Qt will not redraw old lines for you.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • M mihail

        Hi, everybody!

        Host OS: Linux x2004d 5.13.0-27-generic #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
        Target Hardware: IMX8 Toradex Ixora V1.2A
        Target OS: Linux apalis-imx8-06543230 5.4.154-5.5.0+git.c65f1622951c #1 SMP PREEMPT Mon Jan 3 15:58:01 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
        KIT(SDK-Toolchain):
        /opt/tdx-xwayland-rt/5.5.0/sysroots/x86_64-tdxsdk-linux/usr/bin/qmake
        /opt/tdx-xwayland-rt/5.5.0/sysroots/x86_64-tdxsdk-linux/usr/bin/aarch64-tdx-linux/aarch64-tdx-linux-g++
        Example: /home/mihail/Qt/Examples/Qt-5.14.2/widgets/painting/gradients/

        I changed:

        ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent)
            : QWidget(parent), m_shade_type(type), m_alpha_gradient(QLinearGradient(0, 0, 0, 0))
        {
            ...
            setAttribute(Qt::WA_OpaquePaintEvent, true);  // Should not erase the previous one !
            QTimer *timer = new QTimer();
            connect(timer, &QTimer::timeout, this, &ShadeWidget::timerWork);
            timer->start(100);
        }
        void ShadeWidget::timerWork()
        {
            update();
        }
        void ShadeWidget::paintEvent(QPaintEvent *)
        {
            QPainter p(this);
            static int i = 0;
            if(i > width()) i = 0;
            p.setPen(Qt::red);
            p.drawLine(i, 0, i, height() - 1);  // draw the added line by timer
            i++;
        }
        

        Problem: Old drawn lines are erased! Why? How to fix it?
        Please help.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @mihail said in QWidget - the drawn image is erased:

        Why?

        because paintEvent() is used to redraw the widget.

        How to fix it?

        Remember the old lines and draw them in paintEvent()

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • M Offline
          M Offline
          mihail
          wrote on last edited by
          #4

          On a desktop PC (Xubuntu) and on NanoPi M4V 2 (Lubuntu) everything is OK. If you draw the old graphics, processor thread every time, it load up to 100%.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You can also draw on an image, remember this and only draw the new line in the next run. Then paint this image in paintEvent to your widget. This will reduce the #lines to paint.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • M Offline
              M Offline
              mihail
              wrote on last edited by
              #6

              ?:

              painter.drawPixmap(rect, QPixmap::fromImage(image));
              

              The graphic stream is also loaded up to 100% at Full HD.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                Keep the QPixmap rather than execute the conversion each time.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1

                • Login

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