Results 1 to 5 of 5

Thread: Cannot attach QScrollBar to QwtPlot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Question Cannot attach QScrollBar to QwtPlot

    hello,
    Background :
    I have Plot a Histogram on QwtPlot using QwtPlotHistogram. then I have been able to magnify the plot in right direction only. Now as I magnify the plot I need A ScrollBar to view the zoomed data. for this I added a QScrollBar.
    I am trying to attach a QScrollBar to My QwtPlot .

    But I can't connect the QScrollBAr to QwtPlot.

    the code which I am trying is : (this is in MyPlot 's constructor)

    QScrollBar *hScrollBar = new QScrollBar(Qt::Horizontal,plot->canvas());
    connect(hScrollBar,SIGNAL(sliderMoved(double)),thi s->canvas(),SLOT(horizontal_scroll(double)));

    horizontal_scroll is my method as :

    void MyPlot:: horizontal_scroll(double value)
    {
    setAxisScale(2, value, value + 105.0);
    //plot->setAxisScale(0,50,20);
    replot();
    }

    I am not getting where I am going wrong....!!

    Thanx in advance...!

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

    Default Re: Cannot attach QScrollBar to QwtPlot

    You also have to write layout code ( moving + resizing the scrollbar ). If you want to have it on top of the plot canvas you have to implement an event filter catching resize and move events for the canvas.

    Again look at the ScrollZoomer from the realtime example - it does this.

    Uwe

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

    mohini (4th January 2011)

  4. #3
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    1
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Question Re: Cannot attach QScrollBar to QwtPlot

    thanx Uwe ..!
    But, ScrollZoomer implements QWtPlotZoomer whereas I am using QwtPlotMagnifier ...
    Its adding to my confusion ...!!
    Can you please elaborate so that I can get it cleared ...!!

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

    Default Re: Cannot attach QScrollBar to QwtPlot

    Event filtering is a general Qt feature ( see QObject::installEventFilter() ).

    Assuming your plot widget owns your scroll bar, then you have to do something like this:

    Qt Code:
    1. class YourPlot: public QwtPlot
    2. {
    3. public:
    4. YourPlot( ... )
    5. {
    6. ....
    7. m_scrollBar = new QScrollBar( Qt::Horizontal, this );
    8. canvas()->installEventFilter(this);
    9. }
    10.  
    11. virtual bool eventFilter(QObject *object, QEvent *e)
    12. {
    13. if ( object == canvas() )
    14. {
    15. if ( e->type() == QEvent::Move )
    16. {
    17. m_scrollBar->move( ... );
    18. }
    19. if ( e->type() == QEvent::Resize )
    20. {
    21. m_scrollBar->resize( ... );
    22. }
    23. }
    24. return QwtPlot::eventFilter( object, event );
    25. }
    26. };
    To copy to clipboard, switch view to plain text mode 

    But of course you can put your scrollbar also everywhere else independant of the plot canvas geometry.

    Uwe

Similar Threads

  1. attach more widgets to a QScrollArea
    By franco.amato in forum Qt Programming
    Replies: 39
    Last Post: 19th January 2010, 16:47
  2. QSharedMemory won't attach
    By MattPhillips in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2009, 15:45
  3. Replies: 3
    Last Post: 16th May 2009, 10:16
  4. Replies: 6
    Last Post: 14th May 2009, 12:02

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
  •  
Qt is a trademark of The Qt Company.