Menu

#379 Painting issue under Android with Qt 6.9.0

open
nobody
None
5
2025-06-20
2025-04-24
No

Dear qwt team,

I'm migrating some code from Qwt 6.2.0 (compiled with Qt 6.2.2) to Qwt 6.3.0 (compiled with Qt 6.9.0) under Android.

The canvas is not being replotted correctly, I supspect this is due to a Qt bug I reported (https://bugreports.qt.io/browse/QTBUG-136220), even if it happens in Qwt without scrolling, the rendering of the repaint issue is very similar.

When the QwtPlot area is repainted, left and top area remains unchanged (not repainted). The only way to repaint for good is to change orientation of the phone. See the attached video.

Code to easily reproduce:

main.cpp:

#include "mainwindow.h"
#include <QApplication>

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

    return a.exec();
}

mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <boost/thread.hpp>

class QwtPlotCurve;
class QwtPlot;
class QTimer;
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
    void computeNewData();
    void receiveData();

signals:
    void newDataComputed();

private:
    unsigned int m_size;
    double* m_dataX;
    double* m_dataY;

    QwtPlotCurve* m_curve;
    QwtPlot* m_plot;
    QTimer* m_timer;
};

#endif // MAINWINDOW_H

mainwindow.cpp:

#include "mainwindow.h"
#include <qwt_plot.h>
#include <qwt_text.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_canvas.h>

#include <QTimer>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    m_size( 5000 )
{
    connect( this, &MainWindow::newDataComputed, this, &MainWindow::receiveData );

    resize(800,600);

    m_plot = new QwtPlot( QwtText("Data"), this);
    setCentralWidget( m_plot );

    m_dataX = new double[m_size];
    m_dataY = new double[m_size];

    for (unsigned int i = 0; i != m_size; ++i)
    {
        m_dataX[i] = i;
        m_dataY[i] = 0;
    }

    // add curves
    m_curve = new QwtPlotCurve("");
    m_curve->attach( m_plot );

    m_plot->setAxisScale( QwtPlot::xBottom, 0, m_size-1 );
    // when lots of points are visible, drawing is very slow, see https://sourceforge.net/p/qwt/bugs/370/
    m_plot->setAxisScale( QwtPlot::yLeft, 0, 1 ); // slow
    //m_plot->setAxisScale( QwtPlot::yLeft, 0, 100 ); // fast
    QwtPlotCanvas *thecanvas = qobject_cast<QwtPlotCanvas *>( m_plot->canvas() );
    thecanvas->setFrameShape( QFrame::NoFrame );
    thecanvas->setLineWidth( 0 );

    // finally, refresh the plot
    m_plot->replot();

    m_timer = new QTimer(this);
    m_timer->setInterval(100);
    m_timer->setSingleShot(true);
    connect(m_timer, &QTimer::timeout, this, &MainWindow::computeNewData);
    m_timer->start();
}

MainWindow::~MainWindow()
{
    delete [] m_dataX;
    delete [] m_dataY;
}

void MainWindow::computeNewData()
{
    for ( unsigned int i = 0; i != m_size; ++i )
    {
        m_dataY[i] = ((double)rand()) / RAND_MAX; // random number between 0 and 1
    }

    static int count = 0;

    emit newDataComputed();
    if ( count < 30 )
        m_timer->start(); // redraw in 100ms

    count++;
}

void MainWindow::receiveData()
{
    m_curve->setSamples(m_dataX,m_dataY,m_size);

    // finally, refresh the plot
    m_plot->replot();
}
1 Attachments

Discussion

  • Uwe Rathmann

    Uwe Rathmann - 2025-04-24

    -is this an Android specific problem or does it also happens on Linux/X11 ?

    • do you have the same problem when upgrading to Qwt 6.3 without changing the Qt version ?
     
  • Jean Porcherot

    Jean Porcherot - 2025-04-24

    Hello,
    I'm planning to test Linux later, I'll let you know if the problem is visible here

    Did not try 6.3 with previous version of Qt, but I doubt it would have the bug as I see a similar issue even when not using Qwt (https://bugreports.qt.io/browse/QTBUG-136220). I's a Qt 6.9.0 issue I bet.
    But with Qwt, it really makes the whole widget not behave right. The only way I found to have the view be updated was to change phone orientation. Without Qwt, the screen ends up repainting itself when user finger releases the screen. Maybe a repaint somweher could workaround that issue in Qwt.

     
  • Anonymous

    Anonymous - 2025-05-06

    Hello,
    I had the opportunity to do more testing under Android:

    6.2.0 with Qt 6.2.2 works fine
    6.3.0 with Qy 6.2.2 works fine
    6.2.0 with Qt 6.9.0 has the display issue
    6.3.0 with Qt 6.9.0 has the display issue

    So the issue is really a regression between Qt 6.2.2 and Qt 6.9.0.

     
  • Jean Porcherot

    Jean Porcherot - 2025-05-06

    Sorry, posted a reply while not being logged...

    I had the opportunity to do more testing:

    Both qwt 6.2.0 and 6.3.0 works fine with Qt 6.2.2
    Both qwt 6.2.0 and 6.3.0 has the display issue with Qt 6.9.0

    So this is definitely a regression due to Qt upgrade from 6.2.2 to 6.9.0.

    Jean

     
  • Anonymous

    Anonymous - 2025-05-13

    Note that adding m_plot->update(); after m_plot->replot(); fixes the issue.

     
  • Jean Porcherot

    Jean Porcherot - 2025-06-20

    Hello,
    Could test a Linux Ubuntu system and a Raspberry Pi (PiOS). The bug is not present. It's a Android only issue, likelly due to Qt repaint bug (there's many in Qt 6.9.0, like https://bugreports.qt.io/browse/QTBUG-133549,...hopefully it will fix this issue if resolved in a next Qt release)

     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB