Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved]Change the view of widget when hover on QPushButton or other QWidget without inheritance



  • Assume that I have a QPushButton and a QTableView
    When my mouse hover on the QPushButton
    I want to change the appearance of the QTableView
    Could I make this happen without inherit QPushButton
    and override the mouseEvent(or other member function)?

    This kind of mission could be done by QML in a flash
    But QML is not an option before the desktop components release

    Thank you very much



  • You can install an event filter on the QPushButton, which will allow you to preview its mouse move events without the need to subclass. I typically do that when I need to do something like make menus or palettes fly out on hover.



  • Note that if mouse tracking (setMouseTracking) is off for the button, you will only receive mouse events when a mouse button is held down.



  • Thanks to both of you


Log in to reply