Sorry for reviving this thread after so much time, but I still have difficulties with my implementation.
I successfully installed the eventFilter and could also get hold of the resize event so that I can change the number of ticks depending on the size of the scale. This is my current code:
{
if (e
->type
() == QEvent::Resize) {
//calculate the maximum amount of ticks
//"scale" is a pointer to the corresponding scaleDraw
qint32 count = scale->length() / scale->maxLabelWidth(preferences::frequencyAxisLabelFont);
count = count / 4; //calculate reasonable amount of ticks
if (count < 3) //always keep minimum number of ticks
count = 3;
setAxisMaxMajor
(QwtPlot::xBottom, count
);
replot();
}
return false;
}
bool PlotWidget::eventFilter(QObject *object, QEvent *e)
{
if (e->type() == QEvent::Resize)
{
//calculate the maximum amount of ticks
//"scale" is a pointer to the corresponding scaleDraw
qint32 count = scale->length() / scale->maxLabelWidth(preferences::frequencyAxisLabelFont);
count = count / 4; //calculate reasonable amount of ticks
if (count < 3) //always keep minimum number of ticks
count = 3;
setAxisMaxMajor(QwtPlot::xBottom, count);
replot();
}
return false;
}
To copy to clipboard, switch view to plain text mode
Now the problem: The number of actually displayed ticks changes drastically between minimal changes of the window size. I will illustrate it with 2 screenshots:
scale1.jpgscale2.jpg
The left screenshot shows the window with a specific size. For the right screenshot I increased the window size the smallest amount possible using the mouse. Now I have a considerably larger number of ticks. If I further increase the window size (just about 1 pixel) I again have the same amount of ticks as in the left screenshot, and so on...
This results in a "flickering" of the axis ticks while resizing the window.
I am sure this is caused by my (probably very bad) implementation. But I searched all classes available and found no other way to change the number of ticks.
I would be very happy if someone could propose a suitable way to achieve this.
Thank you very much in advance.
Bookmarks