Ich habe bitte eine Frage. Vielleicht kann mir jemand helfen. Vielen Dank im Voraus.
Wenn man einen Plot mit breiten Labels auf der x-Achse hat, dann springt der Plot beim Scrollen in x-Richtung (ähnlich einem Gummibandeffekt).
Beim Recherchieren, warum das so ist, bin ich auf die Lösung gestoßen, dass man
Code: Alles auswählen
plot.axisWidget(QwtPlot::xBottom)->setMinBorderDist();
Gibt es da eine bessere Lösung? Ich hätte u.a. darauf getippt, dass man das Clippen der x-Tick-Labels irgendwie beeinflussen kann, aber anscheinend geht das nicht.
Habe hier ein simples Beispiel, was den Effekt demonstriert:
Code: Alles auswählen
#include <cstdlib>
#include <QApplication>
#include <QTimer>
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
#include "qwt_scale_widget.h"
int main (int argc, char* argv[])
{
QApplication app(argc, argv);
QwtPlot plot;
plot.setTitle( "Plot Demo" );
plot.setCanvasBackground( Qt::white );
// hilft, aber dafür hat die Linie einen unschönen Abstand
// plot.axisWidget(QwtPlot::xBottom)->setMinBorderDist(200, 200);
class ScaleDraw : public QwtScaleDraw
{
private:
QwtText label (double) const override
{
return QwtText("xxxxxxxxxxxxxxx");
}
};
plot.setAxisScaleDraw(QwtPlot::xBottom, new ScaleDraw);
const auto curve = new QwtPlotCurve;
curve->setTitle("Some Points");
curve->setPen( Qt::blue, 4);
curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
QPolygonF points;
std::srand(std::time(nullptr));
const auto random_variable = std::rand();
for (uint64_t x = 0; x != 10'000; ++x)
{
const auto y = static_cast<double>(std::rand()) / RAND_MAX * 1'000.0;
points << QPointF(x, y);
}
curve->setSamples( points );
curve->attach(&plot);
QTimer timer;
timer.setInterval(50);
QObject::connect(&timer, &QTimer::timeout, [&plot]
{
static uint64_t left = 0, right = 300;
plot.setAxisScale(QwtPlot::xBottom, left, right);
plot.replot();
left += 1;
right += 1;
});
timer.start();
plot.showMaximized();
return app.exec();
}