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:03:50
|
Den tis 12 mars 2019 kl 10:59 skrev Uwe Rathmann <Uwe...@ti...>:
>
> > I'm attaching a picture where I've made the canvas background blue to
> > make it clear. The image shows my attempt with overriding paintEvent,
> > note how the "g" is cropped by the canvas which is painted over it.
>
> You have 2 options:
>
> a) Disable the top axis and add a QwtPlotScaleItem instead.
>
> This way the axis would be inside the canvas and you could simply
> overload the label method like posted before without losing any space.
>
> But I'm not sure about this solution as it has a couple of problems, you
> might not want to accept.
>
> b) Add an extra widget for unit text
>
> If you want to draw on top of canvas and scales you need to add an
> additional child widget that is on top of the others:
>
> class UnitLabel : public QWidget
> {
> public:
> UnitLabel( QwtPlot* plot )
> : public QWidget( plot )
> {
> setAttribute( Qt::WindowTransparentForInput, true );
> plot->installEventFilter( this );
>
> adjustSize();
> }
>
> protected:
> void paintEvent( QPaintEvent *event ) override
> {
> const auto plot = qobject_cast< const QwtPlot* >( parent() );
> const auto scaleWidget = plot->axisWidget( QwtPlot::yTop )
>
> QPoint pos = scaleWidget->...
> pos = mapFrom( scaleWidget, pos );
>
> QPainter painter;
> painter.setPen( ... );
> painter.setFont( ... );
> painter.drawText( pos, ... );
> }
>
> bool eventFilter(QObject *object, QEvent *event) override
> {
> if ( object == parent() && event->type() == QEvent::Resize )
> adjustSize();
>
> return QWidget::eventFilter();
> }
>
> private:
> void adjustSize()
> {
> setSize( parentWidget()->size() );
> }
> };
>
> You will also have to write some code for QwtPlotRenderer - but there
> you don't have any issues with clipping.
Many thanks a lot Uwe for your detailed examples, and sorry if I was
unclear from the start.
Now I know what the approaches are. I will see if the "\nUnit" label
approach is sufficient. If not, I will try your second approach here,
since it sounds cleanest even if it's a bit involved.
Elvis
>
> Uwe
>
>
> _______________________________________________
> qwt-interest mailing list
> qwt...@li...
> https://lists.sourceforge.net/lists/listinfo/qwt-interest
|