Re: Draw text on top of both canvas and plot background?
Brought to you by:
rathmann
|
From: Elvis S. <elv...@or...> - 2019-03-12 08:17:27
|
Den tis 12 mars 2019 kl 09:13 skrev Elvis Stansvik
<elv...@or...>:
>
> Den tis 12 mars 2019 kl 09:09 skrev Uwe Rathmann <Uwe...@ti...>:
> >
> > Hi Elvis,
> >
> > > Hope that makes it more clear.
> >
> > That doesn't answer my question, but maybe all you want to do is:
>
> Hm, I'm confused. Your question was "Where exactly do you want to draw
> the extra text", to which I answered
>
> "The desired_result.png image shows where I want to paint the text
> "g/t". I added the text with an image editor. It's right below the top
> axis, right aligned with its max label."
>
> and attached a picture showing exactly where I want to draw the text.
>
> What more info do you need? :p
>
> Elvis
>
> >
> > class YourScaleDraw : public QwtScaleDraw
> > {
> > ....
> >
> > QwtText label( double value ) const override
> > {
> > auto txt = QLocale().toString( value );
> >
> > const auto ticks = scaleDiv().ticks[ QwtScaleDiv::MajorTick ];
> > if ( !ticks.empty() && value == ticks.last() )
> > {
> > txt += "\nUnit";
> > }
> >
> > return txt;
> > }
> > };
The approach you showed here is very valuable though, because as a
backup plan, if it turns out it's not possible to paint the text where
I want it, is to do it like this (modifying, or possibly entirely
replacing one of the top axis labels), so thanks a lot for giving this
example on how to get out the major ticks et.c.
Elvis
> >
> > plot->setAxisScaleDraw( QwtPlot::xTop, new YourScaleDraw() );
>
> That will draw the text inside the top axis. I want to draw it below
> the top axis, straddling the canvas and plot background, as like my
> desired_result.png image shows.
>
> Elvis
>
> >
> > Uwe
|