Results 1 to 2 of 2

Thread: QwtPlotSpectrogram NearestNeighbor with borders or grid?

  1. #1
    Join Date
    Dec 2011
    Posts
    60
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default QwtPlotSpectrogram NearestNeighbor with borders or grid?

    I'm using the QwtPlotSpectrogram in NearestNeighbor mode.

    The issue is that neighboring squares of the same color have no border or divider between them, so the colors blend into each other.



    OPTIONS

    1. I figured one possible solution would be to use a QwtPlotGrid for the divisions. Uwe, you might have also tried this as the "rasterview" example has some QwtPlotGrid code commented out with "#if 0".

    The problems with a QwtPlotGrid were that I had trouble aligning the grid's default state with my divisions (which I'm thinking is solvable), and the fact that the grid is didn't track the square divisions correctly when zooming.

    2. Another option (what would seem to be a perfect solution) would be to by default create a "border" around each square. The border could be black or white, or another specified color. And, a border would correctly track at all zoom levels.
    ------------

    A few questions:

    1. Within the API, is there a way to get borders or divisions between the squares? <I didn't see one>

    2. Am I looking at an enhancement request? An option to add an x-pixel border to the squares in Nearest Neighbor mode doesn't seem like an impossible task. I'd be willing to poke around the source code if needed.

    3. Any other options?

    Thank you,
    Alketi

  2. #2
    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: QwtPlotSpectrogram NearestNeighbor with borders or grid?

    Quote Originally Posted by alketi View Post
    The issue is that neighboring squares of the same color have no border or divider between them, so the colors blend into each other.i
    By squares you are probably talking about data pixels and you want to have a frame around each pixel.
    As your data seems to be organized in equidistant pixels your QwtRasterData object returns a valid pixelHint() ( when using QwtMatrixRasterData this is always the case ).

    So you could try something like this ( completely untested ):

    Qt Code:
    1. class YourSpectrogram: public QwtPlotSpectrogram
    2. {
    3. public:
    4. virtual void draw( QPainter *painter,
    5. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    6. const QRectF &canvasRect ) const
    7. {
    8. QwtPlotSpectrgram::draw( painter, xMap, yMap, canvasRect );
    9. drawGrid( painter, xMap, yMap, canvasRect() );
    10. }
    11.  
    12. private:
    13. void drawGrid( QPainter *painter,
    14. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    15. const QRectF &canvasRect ) const
    16. {
    17. painter->setPen( ... );
    18.  
    19. const QRectF hint = data()->pixelHint();
    20.  
    21. // vertical lines
    22.  
    23. const double x1 = xMap.invTransform( canvasRect.left() );
    24. const double x2 = xMap.invTransform( canvasRect.right() ),
    25.  
    26. // aligning x to the beginning of a pixel
    27. const double x = hint.right() + ( qFloor( ( x1 - hint.right() ) / hint.width() ) + 1 ) * hint.width();
    28.  
    29. for ( ; x < x2, x += hint.width() )
    30. {
    31. const double pos = xMap.transform( x );
    32. painter->drawLine( pos, canvasRect.top(), pos, canvasRect.bottom() );
    33. }
    34.  
    35. // horizontal lines
    36.  
    37. ...
    38. }
    39. };
    To copy to clipboard, switch view to plain text mode 
    HTH Uwe

Similar Threads

  1. XYZ tracker for QwtPlotSpectrogram
    By epsilon in forum Qwt
    Replies: 2
    Last Post: 5th September 2012, 05:53
  2. Google map on QwtPlotSpectrogram
    By sagittager in forum Qwt
    Replies: 4
    Last Post: 15th October 2011, 16:32
  3. widget borders v4.2
    By dacrawler in forum Newbie
    Replies: 0
    Last Post: 24th January 2011, 20:08
  4. QGroupBox borders
    By onurozcelik in forum Qt Programming
    Replies: 0
    Last Post: 27th August 2010, 07:24
  5. Groupbox has no borders ?
    By vieraci in forum Qt Programming
    Replies: 12
    Last Post: 30th April 2009, 13:46

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.