Results 1 to 7 of 7

Thread: QwtPicker with QwtHistogram

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: QwtPicker with QwtHistogram

    QwtPlot is a composite widget, that consists of widgets for title, legend, 4 scales and the canvas. The canvas is the widget in the center, where all plot items ( f.e your histogram ) are painted to. With a picker you can select a polygon a rectangle or a position on the canvas.

    So what you need to do then is to translate the selected coordinate into something that has to do with your data ( this is what you have passed to the histogram item ). F.e iterate over your samples and check if the bounding rectangle of one of your sample contains the clicked coordinate. Then you have the selected bar ( = visual representation of your sample )

    Uwe

  2. #2
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: QwtPicker with QwtHistogram

    It's much much clearer for me now. Thanks for the explanation.

    Using the "event_filter" example I found in the Qwt source, I tried to implement the move event, but it don't works. The "selected" works fine.

    Can I have some help on this piece of code ?

    HistogramPlot.hh
    cpp Code:
    1. #ifndef HISTOGRAMPLOT_HH_
    2. # define HISTOGRAMPLOT_HH_
    3.  
    4. # include <qwt_plot.h>
    5. # include <qwt_picker.h>
    6. # include <qwt_plot_picker.h>
    7.  
    8. class HistogramPlot : public QwtPlot
    9. {
    10. Q_OBJECT
    11. public:
    12. HistogramPlot(QWidget* = 0);
    13.  
    14. private:
    15. void populate();
    16.  
    17. private Q_SLOTS:
    18. void showItem(QwtPlotItem*, bool on);
    19. void moved(const QPoint& pos);
    20. void selected(const QPointF& pos);
    21.  
    22. protected:
    23. QwtScaleDiv fixedNumberScaleDiv() const;
    24. QwtPlotPicker* picker_;
    25. };
    26.  
    27. #endif /* !HISTOGRAMPLOT_HH_ */
    To copy to clipboard, switch view to plain text mode 

    HistogramPlot.cc
    cpp Code:
    1. HistogramPlot::HistogramPlot(QWidget* parent)
    2. : QwtPlot(parent)
    3. {
    4. [...]
    5.  
    6. picker_ = new QwtPlotPicker(this->canvas());
    7. picker_->setStateMachine(new QwtPickerClickPointMachine);
    8. connect(picker_, SIGNAL(moved(const QPoint&)),
    9. SLOT(moved(const QPoint&)));
    10. connect(picker_, SIGNAL(selected(const QPointF&)),
    11. SLOT(selected(const QPointF&)));
    12. }
    13.  
    14. void HistogramPlot::moved(const QPoint& pos)
    15. {
    16. QString info;
    17. info.sprintf("Freq=%g, Ampl=%g, Phase=%g",
    18. invTransform(QwtPlot::xBottom, pos.x()),
    19. invTransform(QwtPlot::yLeft, pos.y()),
    20. invTransform(QwtPlot::yRight, pos.y())
    21. );
    22. qDebug() << info;
    23. }
    24.  
    25. void HistogramPlot::selected(const QPointF& pos)
    26. {
    27. QString info;
    28. info.sprintf("Freq=%g, Ampl=%g, Phase=%g",
    29. invTransform(QwtPlot::xBottom, pos.x()),
    30. invTransform(QwtPlot::yLeft, pos.y()),
    31. invTransform(QwtPlot::yRight, pos.y())
    32. );
    33. qDebug() << info;
    34. }
    To copy to clipboard, switch view to plain text mode 

    Edit: I just understand that "moved" is use when you drag something, not when you move the mouse. I don't found a signal/slot which deal with mouse move. How can I implement that ?
    Last edited by cptpingu; 22nd November 2010 at 17:22.

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: QwtPicker with QwtHistogram

    Maybe QwtPickerTrackerMachine is what you are looking for.

    Uwe

  4. #4
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: QwtPicker with QwtHistogram

    I understand. Problem solved

    Thanks a lot.

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.