Qt QWidget QPainter problem

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 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.

Hi @Mihail75 ,

To get the best support I recommend you try the Qt Forum.

This is out of scope of the Support Toradex provides.

Best Regards
Kevin

Thanks.
But I use two official Toradex images with Qt (with multimedia and Boot2Qt). There is a problem there.
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%.

Hello @Mihail75 ,

Like my colleague @kevin.tx mentioned, this doesn’t directly seem to be an issue with the images offered by Toradex, but rather the nature of the paintEvent() function. This function is called whenever the widget needs to be re-drawn / re-painted, hence why you see your old lines being “erased”.

This very same issue is being discussed in this thread on Qt Community.

I hope it helps!

Best regards,
Janani