Search code examples
qtuser-interfaceanimationqgraphicsscene

Animated GUI with Qt and mouse hover on QGraphicsTextItem


I'm trying to make my own animated GUI with the help of Qt 4.8 on Windows. At the beginning i used the widgets and the Qt Designer to place a horizontal/grid/etc layout and put inside the normal widgets but I found that making them move with the animations framework is not really easy. So I switched to QGraphicsScene/QGraphicsView that seems much simpler to use with animations. I would make a simple menu where there are the main items that when hovered makes visible the submenu items. Something simple, thing about a dropdown horizontal menu. I placed the QGraphicsTextItem items but I still don't understand how could I connect the hover event of the main items to display the submenu items. Any idea? At the moment I have a QMainWindow with a QGraphicsView widget that takes all the area.


Solution

  • You could display the submenu (or do whatever action you want) on hover by creating your own specialized subclass of QGraphicsTextItem and re-implementing the hoverEnterEvent and hoverLeaveEvent methods.

    Make sure you've read the setAcceptHoverEvents documentation so you understand when, and for which items, these events are generated.