Results 1 to 2 of 2

Thread: setScaleDraw(QwtScaleDraw * scaleDraw) function in QwtPlotScaleItem class

  1. #1
    Join Date
    Jun 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default setScaleDraw(QwtScaleDraw * scaleDraw) function in QwtPlotScaleItem class

    Hi, everyone.
    I am using qwt-6.1.0 library. I want to draw scales inside the plot canvas. I have read the example which is given in QwtPlotScaleItem class reference and created a subclass of QwtPlot where in constructor I wrote this:
    Qt Code:
    1. QwtPlotScaleItem *scaleItemY =
    2. new QwtPlotScaleItem(QwtScaleDraw::RightScale);
    3. scaleItemY->setBorderDistance(0);
    4. scaleItemY->attach(this);
    5. this->enableAxis(QwtPlot::yLeft, false);
    6.  
    7. QwtPlotScaleItem *scaleItemX =
    8. scaleItemX->setBorderDistance(0);
    9. scaleItemX->attach(this);
    10. this->enableAxis(QwtPlot::xBottom, false);
    To copy to clipboard, switch view to plain text mode 
    Here everythig is ok. When I attach grid it cross labels, and now I want to shift labels, so that there would be no intersections of grids and labels. For that I have created a subclasses (XScaleDraw and YScaleDraw) of QwtScaleDraw class where i override virtual void drawLabel (QPainter* painter, double value) const function: instead of
    Qt Code:
    1. lbl.draw ( painter, QRect( QPoint( 0, 0 ), labelSize.toSize() ) );
    To copy to clipboard, switch view to plain text mode 
    I wrote (for X shift) :
    Qt Code:
    1. lbl.draw ( painter, QRect( QPoint( 0+(int)(labelSize.width()/2), 0 ), labelSize.toSize() ) );
    To copy to clipboard, switch view to plain text mode 
    and for Y shift:
    Qt Code:
    1. lbl.draw ( painter, QRect( QPoint(0, 0+(int)(labelSize.height()/2) ), labelSize.toSize() ) );
    To copy to clipboard, switch view to plain text mode 
    Now I set scale draw and after that problems arise:
    Qt Code:
    1. QwtPlotScaleItem *scaleItemY =
    2. new QwtPlotScaleItem(QwtScaleDraw::RightScale);
    3. scaleItemY->setScaleDraw(new YScaleDraw);
    4. scaleItemY->setBorderDistance(0);
    5. scaleItemY->attach(this);
    6. this->enableAxis(QwtPlot::yLeft, false);
    7.  
    8. QwtPlotScaleItem *scaleItemX =
    9. scaleItemX->setScaleDraw(new XScaleDraw);
    10. scaleItemX->setBorderDistance(0);
    11. scaleItemX->attach(this);
    12. this->enableAxis(QwtPlot::xBottom, false);
    To copy to clipboard, switch view to plain text mode 
    XScale is drawn at the top (instead of bottom) and YScale is disappeared. Actually it happens even if I don't override virtual void drawLabel (QPainter* painter, double value) const function and create empty subclass of QwtScaleDraw. Any idea what is going on here?

  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: setScaleDraw(QwtScaleDraw * scaleDraw) function in QwtPlotScaleItem class

    You can't change the drawing code without doing the same for the layout code - unfortunatley those methods are not virtual.

    But instead of changing the scale item you could also try to configure the grid not draw over the scale. F.e. in the qwtpolar package the grid calculates a clip region from the bounding rectangles of the scale tick labels before drawing its lines ( have a look at QwtPolarGrid::draw ).

    You could do something similar in YourGrid::draw, but also somewhere in an overloaded QwtPlot::drawItems().

    Uwe

Similar Threads

  1. Replies: 11
    Last Post: 5th September 2012, 20:47
  2. Replies: 1
    Last Post: 13th October 2011, 16:52
  3. Replies: 2
    Last Post: 14th September 2011, 07:53
  4. Replies: 1
    Last Post: 19th August 2011, 08:05
  5. Replies: 3
    Last Post: 16th May 2007, 11:07

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.