I am having QGraphicsScene
which contains many digital gates ( AND,OR,NOR etc ) which are made up of Arc
, Polyline
, Circle
, Straight line
etc.
I am implementing a feature like, when I hover mouse over input of Gates, it's name should be seen on tool tip.
In above screen shot, there is a gate (i2) which has 2 inputs ( top input line is a[2] and bottom input line is a[3] )
When I hover inside Red
line, I get a[3]
as hovering name on cursor tool tip.
And when I hover outside Red
line and inside of Blue
line, I get a[2]
as hovering name on cursor tool tip.
But I am expecting, hovering info will be visible only when I hover on input lines of gates. Why am I getting input line names when I hover around input lines ? And moreover, above hovering info is also wrong.
Here is my code :
bool myViewer::eventFilter(QObject* watched, QEvent* event)
{
case QEvent::MouseMove:
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
QPointF mousePoint = _view->mapToScene(mouseEvent->pos());
QGraphicsItem* SelectedItem = scene->itemAt(mousePoint, QTransform());
if(SelectedItem)
{
myPoly* item = qgraphicsitem_cast<myPoly*>(SelectedItem);
if(item)
{
item->setToolTip(item->GetPolyLineName()); // GetPolyLineName gives name as a[2] or a[3]
}
}
}
break;
}
myPoly.h
class myPoly : public QGraphicsPathItem {
public:
QString &GetPolyLineName();
}