Draw inward tick in QwtPlot scaleDraw
<p>How can we draw axis tick marks in both inward and outwards? I reimplemented QwtScaleDraw and overrode with drawTick but I don't know how to match the tick position and draw additional line using</p>

<pre><code>QwtPainter::drawLine(painter,QPointF,QPointF)
</code></pre>

<p>I tried :</p>

<pre><code>inside Plot::drawItems(QPainter *painter, const QRectF &amp;rect, const QwtScaleMap map[axisCnt]) const

const QwtScaleMap &amp;map;
for (j = 0; j &lt; majTicks; j++)
{
   y = map.transform(majTickList[j]);
  QwtPainter::drawLine(painter, x, y, x + m_majTickLength, y);
}
</code></pre>

<p>but the axis margin is not matching with the corners of the out axis, small deviation is coming. I took a screenshot here :</p>

<p><a href="https://i.stack.imgur.com/u106A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u106A.png" alt="enter image description here"></a></p>

<p>my complete drawInward</p>

<pre><code>    void CustomScaleDraw::draw(QPainter *painter, const QPalette &amp;palette) const
    {


        QwtScaleDraw::draw(painter, palette);


        painter-&gt;save();

        QPen pen = painter-&gt;pen();
        pen.setColor(palette.color(QPalette::Foreground));
        painter-&gt;setPen(pen);

        int majLen = m_pPlotWidget-&gt;majorTickLength();
        if (m_majTickStyle &gt;= Both &amp;&amp; majLen &gt; 0){
            QList&lt;double&gt; ticks = this-&gt;scaleDiv().ticks(QwtScaleDiv::MajorTick);
            for (int i = 0; i &lt; (int)ticks.count(); i++){
                const double v = ticks[i];
                if (this-&gt;scaleDiv().contains(v))
                    drawInwardTick(painter, v, majLen);
            }
        }
    }


and 
void CustomScaleDraw::drawInwardTick(QPainter *painter, double value, int len) const
{


    int pw2 = qMin((int)painter-&gt;pen().width(), len) / 2;

    QwtScaleMap scaleMap = this-&gt;scaleMap();

    QPointF pos = this-&gt;pos();

    int majLen = tickLength(QwtScaleDiv::MajorTick);


    const int clw = m_pPlotWidget-&gt;lineWidth();
    const int tval = scaleMap.transform(value);

    bool draw = false;
    if ( orientation() == Qt::Vertical ){
        int low = (int)scaleMap.p2() + majLen;
        int high = (int)scaleMap.p1() - majLen;
        if ((tval &gt; low &amp;&amp; tval &lt; high) ||
            (tval &gt; high &amp;&amp; !m_pPlotWidget-&gt;axisEnabled (QwtPlot::xBottom) &amp;&amp; !clw) ||
            (tval &lt; low &amp;&amp; !m_pPlotWidget-&gt;axisEnabled(QwtPlot::xTop) &amp;&amp; !clw)) draw = true;
    } else {
        int low = (int)scaleMap.p1() + majLen;
        int high = (int)scaleMap.p2() - majLen;
        if ((tval &gt; low &amp;&amp; tval &lt; high) ||
            (tval &gt; high &amp;&amp; !m_pPlotWidget-&gt;axisEnabled(QwtPlot::yRight) &amp;&amp; !clw) ||
            (tval &lt; low &amp;&amp; !m_pPlotWidget-&gt;axisEnabled(QwtPlot::yLeft) &amp;&amp; !clw)) draw = true;
    }

    if (draw){

        switch(alignment()){

            case LeftScale:
            {
                QwtPainter::drawLine(painter, pos.x() + pw2, tval, pos.x() + len, tval);

                break;
            }
            case RightScale:
            {
                QwtPainter::drawLine(painter, pos.x() - pw2, tval, pos.x() - len, tval);
                break;
            }
            case BottomScale:
            {
                QwtPainter::drawLine(painter, tval, pos.y() - pw2, tval, pos.y() - len);
                break;
            }
            case TopScale:
            {
                QwtPainter::drawLine(painter, tval, pos.y() + pw2, tval, pos.y() + len);
                break;
            }
        }
    }
//    QwtPainter::setMetricsMap(metricsMap); // restore metrics map
}
</code></pre>

<p>my scale setup in QwtPlot.cpp</p>

<p>for (int i = 0; i &lt; QwtPlot::axisCnt; i++)
    {
        QwtScaleWidget *scale = (QwtScaleWidget *) axisWidget(i);</p>

<pre><code>    if(scale)
    {
        scale-&gt;setMargin(0);

        //the axis title color must be initialized...
        QwtText title = scale-&gt;title();
        title.setColor(Qt::black);
        scale-&gt;setTitle(title);

        //...same for axis color
        QPalette pal = scale-&gt;palette();
        pal.setColor(QPalette::Foreground, QColor(Qt::black));
        scale-&gt;setPalette(pal);

        CustomScaleDraw *sd = new CustomScaleDraw(this);
        sd-&gt;setTickLength(QwtScaleDiv::MinorTick, m_minTickLength);
        sd-&gt;setTickLength(QwtScaleDiv::MediumTick, m_minTickLength);
        sd-&gt;setTickLength(QwtScaleDiv::MajorTick, m_majTickLength);

        setAxisScaleDraw(i,sd);

    }
}
plotLayout()-&gt;setAlignCanvasToScales( true );
</code></pre>

<p>m_minTickLength = 5;
  m_majTickLength = 9;</p>