i mean QwtPlotMarker. the label for QwtPlotMarker should re-adjust automatically in case if i move the mouse over a datapointer beeing at the outer corner...
do you know what i try to achieve?
here is the snipped i have at the moment:
std::shared_ptr<QwtPlot> plot;
std::shared_ptr<QwtPlotCurve> curve1;
std::shared_ptr<QwtPlotCurve> curve2;
std::shared_ptr<QwtPlotMarker> marker;
std::shared_ptr<QwtPlotShapeItem> plotItem;
///////////////////
{
if (event
->type
() == QEvent::MouseMove) {
QwtPlotItemList curves
= plot.
get()->itemList
(QwtPlotItem::Rtti_PlotCurve);
if (curves.size() == 0) {
return false;
}
double dist1 = 1e99;
double dist2 = 1e99;
int point_index1
= static_cast<QwtPlotCurve
*>
(curves
[0])->closestPoint
(QPoint(m
->x
(), m
->y
()),
&dist1
);
int point_index2
= static_cast<QwtPlotCurve
*>
(curves
[1])->closestPoint
(QPoint(m
->x
(), m
->y
()),
&dist2
);
if (point_index1 != -1 && point_index2 != -1) {
if (dist1 < dist2) {
p = static_cast<QwtPlotCurve*>(curves[0])->sample(point_index1);
}
else {
p = static_cast<QwtPlotCurve*>(curves[1])->sample(point_index2);
}
//marker->setSpacing(10);
marker
->setLinePen
(QPen(Qt
::black,
2, Qt
::DotLine));
marker
->setLabel
("t: " + QString::number(p.
x()) + ", Volts: " + QString::number(p.
y()));
marker->setLabelAlignment(Qt::AlignRight | Qt::AlignTop); // | Qt::AlignCenter);
//marker->setLabelAlignment(Qt::AlignCenter | Qt::AlignCenter);
marker->setXValue(p.x());
marker->setYValue(p.y());
}
marker->attach(plot.get());
plot->replot();
}
return false;
}
std::shared_ptr<QwtPlot> plot;
std::shared_ptr<QwtPlotCurve> curve1;
std::shared_ptr<QwtPlotCurve> curve2;
std::shared_ptr<QwtPlotMarker> marker;
std::shared_ptr<QwtPlotShapeItem> plotItem;
///////////////////
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseMove)
{
QMouseEvent *m = static_cast<QMouseEvent*>(event);
QwtPlotItemList curves = plot.get()->itemList(QwtPlotItem::Rtti_PlotCurve);
if (curves.size() == 0) {
return false;
}
double dist1 = 1e99;
double dist2 = 1e99;
int point_index1 = static_cast<QwtPlotCurve*>(curves[0])->closestPoint(QPoint(m->x(), m->y()), &dist1);
int point_index2 = static_cast<QwtPlotCurve*>(curves[1])->closestPoint(QPoint(m->x(), m->y()), &dist2);
if (point_index1 != -1 && point_index2 != -1) {
QPointF p;
if (dist1 < dist2) {
p = static_cast<QwtPlotCurve*>(curves[0])->sample(point_index1);
}
else {
p = static_cast<QwtPlotCurve*>(curves[1])->sample(point_index2);
}
//marker->setSpacing(10);
marker->setLineStyle(QwtPlotMarker::Cross);
marker->setLinePen(QPen(Qt::black, 2, Qt::DotLine));
marker->setLabel("t: " + QString::number(p.x()) + ", Volts: " + QString::number(p.y()));
marker->setLabelAlignment(Qt::AlignRight | Qt::AlignTop); // | Qt::AlignCenter);
//marker->setLabelAlignment(Qt::AlignCenter | Qt::AlignCenter);
marker->setXValue(p.x());
marker->setYValue(p.y());
}
marker->attach(plot.get());
plot->replot();
}
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks