Results 1 to 7 of 7

Thread: QwtPicker with QwtHistogram

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

    Default QwtPicker with QwtHistogram

    Hi.

    I'm using Qwt 6.0.0-rc2, with Qt4.7 on Arch Linux.

    I have a QwtPlotHistogram and I want to select one of the histogram, ie if I click on a histogram an action is triggered (like showing a message box).
    I see QwtPicker is made for this kind of task. I read the documentation of QwtPlotPicker, and it was clearly made for QwtPlot.
    Is there a QwtPicker which works for QwtPlotHistogram ?

    Is there a better solution to accomplish what I want to do ?

    Many thanks.

  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: QwtPicker with QwtHistogram

    A picker is basically an event filter for mouse and key events on the plot canvas combined with tracker text and rubberband to provide some visual feedback for the user interaction.

    In your case it looks like you want a picker with a QwtPickerClickPointMachine. Then you can implement a slot ( connected to QwtPlotPicker::selected( const QPointF &pos ) ) where you can identify the bar from the selected position and then trigger your action.

    Uwe

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

    cptpingu (22nd November 2010)

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

    Default Re: QwtPicker with QwtHistogram

    Hi Uwe.

    Thanks for the answer.

    I'm a beginner in Qwt, and I don't understand what I should do. I search on Google to find example with QwtPickerClickPointMachine, but I can't find any tutorial. Moreover, the documentation is not helping me.

    I have some questions:
    - You want me to use QwtPickerClickPointMachine to make a bridge between QwtPlotPicker and QwtHistogram ?
    - If so, how can I initialize QwtPlotPicker ? It needs a canvas, but I don't found where I can get a canvas from a QwtHistogram.
    - Can I have an example of a QwtPickerClickPointMachine asociated with a QwtHistogram (I can't find one on the web) ?

    Thank you.

  5. #4
    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: 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

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

    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 16:22.

  7. #6
    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: QwtPicker with QwtHistogram

    Maybe QwtPickerTrackerMachine is what you are looking for.

    Uwe

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

    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.