Results 1 to 2 of 2

Thread: QwtPlotMagnifier not working with push buttons

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QwtPlotMagnifier not working with push buttons

    Hello Uwe and others,

    I wanted to implement a Qwt graph aplication with zooming capabilities, and I know that QwtPlotMagnifier is the right guy to do such a job. The problem is that the user won't have a mouse and neither a keyboard to do the scrolling/zooming effects, having only a touchscreen with a "+" and a "-" pushbuttons.

    Looking at the Qwt assistant files, I noticed that there was no "zoom in" and "zoom out" slots to which I could connect the clicked() signal from my two pushbuttons (using Qwt 6.0.2). Any reasons why? Wouldn't it be a good idea to have them?

    But anyway, I later thought that I should implement the setZoomInKey and setZoomOutKey methods with some given key and then configure my pushbuttons with that same key using the QAbstractButton::setShortcut method. Later I noticed that wouldn't work, but before noticing this I tested the system and I figured out not only that the graph didn't react with the pressing of the buttons (expected), but also that when using the keyboard the magnifier wouldn't work as well.

    I managed to make my zooming work by creating a zoomIn() slot on the graph and calling setAxysScale(QwtPlot::xBottom,0,value() +- 50) and it's working fine, but I'm still curious why the QwtPlotManager implementation didn't work when the keyboard was used, as well as if there is another way to use QwtPlotManager instead of calling setAxisScale to do this in the mentioned situation.


    Thanks,


    Momergil
    May the Lord be with you. Always.

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

    Default Re: QwtPlotMagnifier not working with push buttons

    QwtPlotMagnifier is about connecting key and mouse events to rescale operations. In your case only the rescale operation is left, what is only some code around setAxisScale:

    Qt Code:
    1. void rescale( QwtPlot* plot, double factor )
    2. {
    3. factor = qAbs( factor );
    4. if ( factor == 1.0 || factor == 0.0 )
    5. return;
    6.  
    7. bool doReplot = false;
    8.  
    9. const bool autoReplot = plot->autoReplot();
    10. plot->setAutoReplot( false );
    11.  
    12. for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    13. {
    14. const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId );
    15.  
    16. const double center = scaleDiv.lowerBound() + scaleDiv.range() / 2;
    17. const double width_2 = scaleDiv.range() / 2 * factor;
    18.  
    19. plot->setAxisScale( axisId, center - width_2, center + width_2 );
    20. doReplot = true;
    21. }
    22.  
    23. plot->setAutoReplot( autoReplot );
    24.  
    25. if ( doReplot )
    26. plot->replot();
    27. }
    To copy to clipboard, switch view to plain text mode 

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

    Momergil (23rd April 2014)

Similar Threads

  1. mouse event not working in buttons
    By meenu in forum Newbie
    Replies: 2
    Last Post: 22nd August 2011, 10:52
  2. Replies: 2
    Last Post: 14th July 2011, 15:17
  3. tab order not working properly for radio buttons
    By netmat in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2010, 14:58
  4. Replies: 1
    Last Post: 19th May 2007, 05:19
  5. Problem with Parent QWidget and Buttons not working
    By VireX in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2007, 22:24

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.