jkriege2 / JKQtPlotter

an extensive Qt5 & Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
http://jkriege2.github.io/JKQtPlotter/index.html
GNU Lesser General Public License v2.1
889 stars 190 forks source link

Add ability to disable delayed resize event #100

Closed fpalazzolo closed 1 year ago

fpalazzolo commented 1 year ago

The delayed resize event might help with large datasets, but it makes the plot jump around. Setting the delay to zero doesn't make this go away either, because the timer mechanism is still enabled.

For my use case, I would like the resizing to be smooth. I propose the following change, which just bypasses the resize timer if the value is set to 0:

in jkqtplotter.cpp:

void JKQTPlotter::resizeEvent(QResizeEvent *event) {
#ifdef JKQTBP_AUTOTIMER
    JKQTPAutoOutputTimer jkaaot(QString("JKQTPlotter::resizeEvent()"));
#endif
    //qDebug()<<"resizeEvent  old="<<size()<<"   new="<<event->size();
     QWidget::resizeEvent(event);
     event->accept();

     // NEW CODE STARTS HERE
     if (jkqtp_RESIZE_DELAY == 0) {
         emit widgetResized(width(), height(), this);
         redrawPlot();
         return;
     }
     // NEW CODE ENDS HERE

I can create a pull request if needed/desired

fpalazzolo commented 1 year ago

I'm sorry, that last bit of code was incorrect. A working addition is here...

in jkqtplotter.cpp, at the bottom of resizeEvent(), change:

     if (sizeChanged) {
        resizeTimer.setSingleShot(true);
        resizeTimer.start(jkqtp_RESIZE_DELAY);
     }

to

     if (sizeChanged) {
        if (jkqtp_RESIZE_DELAY == 0) {
            // Do this now
            delayedResizeEvent();
        } else {
            resizeTimer.setSingleShot(true);
            resizeTimer.start(jkqtp_RESIZE_DELAY);
        }
     }
jkriege2 commented 1 year ago

Hi! that sounds like a good idea ... and I would be happy to receive a PR ... Could you also explain this in the documentation of jkqtp_RESIZE_DELAY? Thanks, JAN