Re: Draw text on top of both canvas and plot background?
Brought to you by:
rathmann
|
From: Elvis S. <elv...@or...> - 2019-03-12 10:33:03
|
Den tis 12 mars 2019 kl 11:32 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:
> >
> > 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;
> > }
> > };
> >
> > plot->setAxisScaleDraw( QwtPlot::xTop, new YourScaleDraw() );
>
> I tried this approach out, but the problem then is the text gets
> cropped at the bottom (probably fixable), and that the text is not
> right-aligned (I tried setRenderFlags(Qt::AlignRight) on the returned
> QwtText). See attached screenshot.
Forgot the attachment, here it is.
Elvis
>
> I'll try your other suggestion with a separate child widget for the
> unit instead.
>
> Elvis
>
> >
> > Uwe
|