Yes these lines are related to plot position, but now I have transform line position into widget pixel format.
I have tried with some solution but its acting weird.
I have one structure below to set/create line using QwtPlotMarker,
{
public:
LineStyle style,
QPen pen
= QPen(Qt
::blue,
1, Qt
::DashDotLine)) : {
setSymbol(sym);
setLabel(label);
setTitle(label);
setValue(value);
setLabelOrientation(orientation);
setLinePen(pen);
setLineStyle(style);
setLabelAlignment(Qt::AlignRight|Qt::AlignBottom);
setRenderHint
(QwtPlotItem::RenderHint::RenderAntialiased);
setLegendIconSize
(QSize(20,
30));
}
};
class Line: public QwtPlotMarker
{
public:
Line(QwtText label, const QPointF value, Qt::Orientation orientation,
LineStyle style, QPen pen = QPen(Qt::blue, 1, Qt::DashDotLine)) :
QwtPlotMarker()
{
setSymbol(sym);
setLabel(label);
setTitle(label);
setValue(value);
setLabelOrientation(orientation);
setLinePen(pen);
setLineStyle(style);
setLabelAlignment(Qt::AlignRight|Qt::AlignBottom);
setItemAttribute(QwtPlotItem::Legend, true);
setRenderHint(QwtPlotItem::RenderHint::RenderAntialiased);
setLegendIconSize(QSize(20,30));
}
QwtSymbol *sym = new QwtSymbol(QwtSymbol::Diamond,QBrush(Qt::red),QPen(Qt::red),QSize(5,5));
};
To copy to clipboard, switch view to plain text mode
I have created vertical line and set position on left side say, 200 and on right side say, 800,
m_line[0]->attach(m_plot);
m_line[1]->attach(m_plot);
m_line[0] = new Line(QwtText("VLine1"), QPointF(200,0), Qt::Vertical, QwtPlotMarker::VLine);
m_line[0]->attach(m_plot);
m_line[1] = new Line(QwtText("VLine2"), QPointF(800,0), Qt::Vertical, QwtPlotMarker::VLine);
m_line[1]->attach(m_plot);
To copy to clipboard, switch view to plain text mode
Now on scroll (wheel) event, I have setting it to the border of the widget,
{
switch(e->type())
{
m_line
[0]->setValue
(QPoint(m_plot
->invTransform
(QwtPlot::xBottom, m_plot
->transform
(QwtPlot::xBottom, m_grid
->xScaleDiv
().
interval().
minValue())+20),
0));
m_line
[1]->setValue
(QPoint(m_plot
->invTransform
(QwtPlot::xBottom, m_plot
->transform
(QwtPlot::xBottom, m_grid
->xScaleDiv
().
interval().
maxValue())-20),
0));
break;
}
}
bool OscilloscopeWidget::eventFilter(QObject *object, QEvent *e)
{
switch(e->type())
{
case QEvent::Wheel:
m_line[0]->setValue(QPoint(m_plot->invTransform(QwtPlot::xBottom, m_plot->transform(QwtPlot::xBottom, m_grid->xScaleDiv().interval().minValue())+20),0));
m_line[1]->setValue(QPoint(m_plot->invTransform(QwtPlot::xBottom, m_plot->transform(QwtPlot::xBottom, m_grid->xScaleDiv().interval().maxValue())-20),0));
break;
}
}
To copy to clipboard, switch view to plain text mode
I have set offset of 20 just to keep line within the widget not on the border.
On Zoom, the Right line is working fine and stays at Right border and on deep zoom out comes into center(at 500)(No problem).
The Left line on zoom out stays on the border(until scale on the border is near 498) but after some time gets vanishes behind the widget.
Why the Left one is hidden behind the widget, why its not set center on deep zoom out ?
what I'm missing here, as Right line working fine but not Left one ?
Bookmarks