Results 1 to 8 of 8

Thread: Labels on QwtPlot

  1. #1
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Labels on QwtPlot

    I'm overloading the drawCanvas method to display text on my QwtPlotHistogram. However when i zoom or scroll the text remains in a fixed position. I want the text to move along with the rectangles of the histogram when i scroll or zoom

  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: Labels on QwtPlot

    Of course you have to align your labels to the translated positions ( QwtScaleMap::transform ).

    When you overload QwtPlotHistogram::draw instead you already have the maps - otherwise you get them using QwtPlot::canvasMap.

    Uwe

  3. #3
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Labels on QwtPlot

    Could you point me to an example where this is done or QwtScaleMap has been used?

  4. #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: Labels on QwtPlot

    Qwt ?

    Uwe

  5. #5
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Labels on QwtPlot

    By example i mean some Qwt code where this has been implemented.. i cannot understand how to use it in my code..

  6. #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: Labels on QwtPlot

    Plot items implemented in Qwt doesn't differ from those, that are implemented in application code.

    Uwe

  7. #7
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Labels on QwtPlot

    Which application?

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Labels on QwtPlot

    Quote Originally Posted by penny View Post
    I'm overloading the drawCanvas method to display text on my QwtPlotHistogram. However when i zoom or scroll the text remains in a fixed position. I want the text to move along with the rectangles of the histogram when i scroll or zoom
    What coordinates are you using for the text? Pixels or data coordinates? If you are using pixels, then of course the text will not move. So you need to define the text location in data coordinates, and use QwtScaleMap to transform the data coordinates into pixels when drawing.

    Look at the Qwt source code for any QwtPlotItem class to see how to use the scale maps. QwtPlotCurve::drawSticks() (from Qwt 5.2) is a simple example:

    Qt Code:
    1. 00730 void QwtPlotCurve::drawSticks(QPainter *painter,
    2. 00731 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    3. 00732 int from, int to) const
    4. 00733 {
    5. 00734 int x0 = xMap.transform(d_data->reference);
    6. 00735 int y0 = yMap.transform(d_data->reference);
    7. 00736
    8. 00737 for (int i = from; i <= to; i++)
    9. 00738 {
    10. 00739 const QwtDoublePoint sample = d_series->sample(i);
    11. 00740 const int xi = xMap.transform(sample.x());
    12. 00741 const int yi = yMap.transform(sample.y());
    13. 00742
    14. 00743 if (orientation() == Qt::Horizontal)
    15. 00744 QwtPainter::drawLine(painter, x0, yi, xi, yi);
    16. 00745 else
    17. 00746 QwtPainter::drawLine(painter, xi, y0, xi, yi);
    18. 00747 }
    19. 00748 }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Labels on axis.
    By eugene in forum Qwt
    Replies: 5
    Last Post: 6th August 2010, 13:30
  2. Replies: 14
    Last Post: 20th April 2010, 11:40
  3. Replies: 1
    Last Post: 16th March 2010, 15:23
  4. Replies: 6
    Last Post: 14th May 2009, 12:02
  5. rotated labels
    By jayw710 in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2006, 17:47

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.