Draw text on top of both canvas and plot background?
Brought to you by:
rathmann
|
From: Elvis S. <elv...@or...> - 2019-03-11 10:37:48
|
Hi,
I'm trying to do something a bit unorthodox, and was hoping someone could
offer some advice.
I'd like to draw some text (the plot unit) right below the top X axis. The
problem is that the place where I want to draw it straddles both the canvas
and the plot background.
This drawn sketch shows where I want to draw the text "g/t":
[image: desired_result.png]
As you can see, it's visible on both the canvas area and the background.
Thus I can't do this inside drawItems(..), since the text would be cropped
to the canvas area.
I tried overriding the paintEvent in my QwtPlot subclass with:
void ConcentrationsPlot::paintEvent(QPaintEvent *event)
{
QwtPlot::paintEvent(event);
const auto topAxis = axisWidget(QwtPlot::xTop);
auto unitRect = rect();
unitRect.setTopRight(topAxis->mapTo(this,
topAxis->rect().bottomRight()));
QPainter painter(this);
painter.setFont(font());
painter.drawText(unitRect, "g/t", Qt::AlignTop | Qt::AlignRight);
}
But the problem then is that the left part of the text gets overpainted by
the canvas:
[image: overpainted.png]
Is there anything I can do here? Is there no way to paint completely on top
of the QwtPlot as a whole?
Very thankful for any advice on how to achieve what I want.
Cheers,
Elvis
|