c++ - Custom Qt QGraphicsItem tooltip -
i'm looking ways implement simple custom tooltip qgraphicsitem
.
i know can use settooltip
set text tooltip. want change text dynamically when mouse hovers @ different parts of qgraphicsitem
object.
what i'm thinking when event qevent::tooltip
, change tooltip text in event handler. however, cannot find event function recieve qevent::tooltip
qgraphicsitem
.
or there ways handle event mouse hovers 2 seconds.
how can make it?
you implement hovermoveevent
in derived qgraphicsitem
class, , set tooltip based on position within graphics item
void myitem::hovermoveevent(qgraphicsscenehoverevent* event) { qpointf p = event->pos(); // use p.x() , p.y() set tooltip accrdingly, example: if (p.y() < height()/2) settooltip("upper half"); else settooltip("bottom half"); }
notice have enable hover events item.
Comments
Post a Comment