Results 1 to 2 of 2

Thread: Sharing on QwtPlotPicker showing values of dual Y axes

  1. #1
    Join Date
    Sep 2010
    Posts
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb Sharing on QwtPlotPicker showing values of dual Y axes

    I have a plot with both Y axes enabled, but find the picker by default will only show value of either one.
    After a while I have figured out a solution, though may not be elegant.


    At the beginning I thought of having two QwtPlotPicker showing each axis but then it turns out their labels overlap and I could not control the label position.
    So I came up with another thought: Modify what the picker displays on its label.

    I first sub-class QwtPlotPicker.
    I was thinking about overriding updateDisplay() then draw the label manually.
    However after reading the source I know that I could override trackerText() which is a virtual function.

    In the class header:
    Qt Code:
    1. protected:
    2. virtual QwtText trackerText(QPoint const &pos) const;
    To copy to clipboard, switch view to plain text mode 

    For the implementation of trackerText(), all I need is to return a text with both Y axes value but the problem is how.
    A picker must know also the Y value of the other picker, so I passed a reference of the other picker in the constructor.

    Qt Code:
    1. protected:
    2. QwtPlotPicker *alt_picker;
    To copy to clipboard, switch view to plain text mode 

    In trackerText(), I get the Y value of alt_picker by calling its trackerText() function.
    QwtPlotPicker::trackerText() is protected so I instead call QwtPicker::trackerText().
    I actually re-organized the text content of both picker but here is a simple append solution.

    Qt Code:
    1. QwtText const &alt_text = ((QwtPicker*)(alt_picker))->trackerText(alt_picker->trackerPosition());
    2. QString alt_y(alt_text.text().split(",").at(1));
    3. QString result(QwtPlotPicker::trackerText(pos).text() + ", " + alt_y);
    4. return QwtText(result);
    To copy to clipboard, switch view to plain text mode 

    I do not know if there is a better way and I would love to know.
    At least it works for me and it is not that cumbersome.

  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: Sharing on QwtPlotPicker showing values of dual Y axes

    Quote Originally Posted by davey View Post
    For the implementation of trackerText(), all I need is to return a text with both Y axes value but the problem is how.
    You can use the canvas maps:

    Qt Code:
    1. virtual QwtText YourPicker::trackerText(const QwtDoublePoint &pos) const
    2. {
    3. QPointF p = transform(pos);
    4.  
    5. int axis = (yAxis() == QwtPlot::yRight) ? QwtPlot::yLeft : QwtPlot::yRight:
    6. double y2 = plot()->canvasMap(axis).invTransform(p.y());
    7.  
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 

    In your special situation, where you simple append the second y value to the text you could also do the following:

    Qt Code:
    1. virtual QwtText YourPicker::trackerText(const QPoint &pos) const
    2. {
    3. int axis = (yAxis() == QwtPlot::yRight) ? QwtPlot::yLeft : QwtPlot::yRight:
    4. double y2 = plot()->canvasMap(axis).transform(p.y());
    5.  
    6. QwtText text = QwtPlotPicker::trackerText(pos);
    7. text += ...
    8. return text:
    9. }
    To copy to clipboard, switch view to plain text mode 

    Uwe

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

    C403 (25th January 2015)

Similar Threads

  1. Replies: 2
    Last Post: 25th February 2010, 10:28
  2. Replies: 4
    Last Post: 17th October 2009, 22:31
  3. Dual frame buffers /dev/fb0 and /dev/fb1
    By ghassett in forum Qt Programming
    Replies: 0
    Last Post: 28th May 2009, 18:57
  4. changing values for one class and showing it ..!
    By salmanmanekia in forum General Programming
    Replies: 6
    Last Post: 14th August 2008, 13:13
  5. Dual TCP/IP Client/Server
    By jimroos in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2007, 21:58

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.