Results 1 to 6 of 6

Thread: Automatic update of scale division on resize of plot widget

  1. #1
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Automatic update of scale division on resize of plot widget

    Hi,

    I'm having the following problem:

    When I resize my application window (which contains a QwtPlot) I would like the scale division to be updated according to the new dimensions. This means that, e.g if the window size is increased, the proper scale division is recalculated and new major ticks are introduced because of the newly created "free space" between the ticks. And of course, vice versa if one shrinks the window size.

    Please bear with me if I am missing something obvious

    Many thanks for any help

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Automatic update of scale division on resize of plot widget

    See QwtPlotRescaler and the navigation example.

    Uwe

  3. #3
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Automatic update of scale division on resize of plot widget

    Thanks for pointing me to the navigation example. I read the code and compiled it, but none of the available resize policies does what I want:

    If the limits of one scale are fixed (for example the y axis while "fitting" is selected), the scale division does not change and the major ticks stay the same during resizing the window. In case that the limits of the scales are not fixed (for example for both axes while "expanding" is selected) the scale division changes and the major ticks are set appropriately, but I don't want the limits of the scales to change during the resize event.

    What I would like to yield is that the limits of both axes stay exactly the same while resizing the plot (as it is the case without using a QwtPlotRescaler) but the number of major (and minor) ticks within these fixed limits should be increased when the plot is stretched (as there is more space for ticks and labels) and decreased when the plot is shrunk (since there is less space for ticks and labels).

    Is there a way to do this?

  4. #4
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Automatic update of scale division on resize of plot widget

    The description of my problem might be a little bit confusing, therefore I will illustrate it with two screenshots.

    In the first picture, my application window is very small and the number of major ticks (0,5,10,15) seems well chosen and the available screen space is filled optimal with the ticks.

    In the second picture, I resized the very same window to the full width of my screen. My problem is, that the number of ticks and labels is still exactly the same as in the small window. The spacing between the ticks is now very big and does not seem well chosen to me. There is enough space to add more major (and minor) ticks (lets say -2, 0,2,4,6,8 and so on), which would result in a much more adequate looking axis.
    window_small.pngwindow_big.jpg

    Is there a way to recalculate the number of ticks whenever the window gets resized?

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Automatic update of scale division on resize of plot widget

    Install an eventFilter for the scale widgets and handle the resize events. There you can change the scale division using the regular Qwt APIs. Maybe it's worth to reimplement QwtPlot::minimumSizeHint as it depends on the scale widgets ( and its ticks and labels ) in the first place.

    Uwe

  6. The following user says thank you to Uwe for this useful post:

    mariposa (12th September 2010)

  7. #6
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Automatic update of scale division on resize of plot widget

    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:

    Qt Code:
    1. bool PlotWidget::eventFilter(QObject *object, QEvent *e)
    2. {
    3. if (e->type() == QEvent::Resize)
    4. {
    5. //calculate the maximum amount of ticks
    6. //"scale" is a pointer to the corresponding scaleDraw
    7. qint32 count = scale->length() / scale->maxLabelWidth(preferences::frequencyAxisLabelFont);
    8. count = count / 4; //calculate reasonable amount of ticks
    9. if (count < 3) //always keep minimum number of ticks
    10. count = 3;
    11. setAxisMaxMajor(QwtPlot::xBottom, count);
    12. replot();
    13.  
    14. }
    15. return false;
    16. }
    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.

Similar Threads

  1. Automatic scale of Graphics View
    By mirelon in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2010, 21:36
  2. Scale division problem
    By Indalo in forum Qwt
    Replies: 0
    Last Post: 2nd December 2009, 08:36
  3. Replies: 5
    Last Post: 27th September 2009, 12:55
  4. qwp plot axis scale
    By Cal in forum Qwt
    Replies: 1
    Last Post: 11th May 2009, 17:10
  5. how to hide the scale in qwt plot
    By babu198649 in forum Qwt
    Replies: 2
    Last Post: 7th March 2008, 06:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.