4
votes

I have a QFormLayout where the left widgets are QLabels and the right widgets are of various types. I want to get notified when the mouse enters any part of a form-row, so I can display an explanation of that row in my statusbar.

Currently I have a QLabel subclass called HoverableLabel which exposes "mouseEntered" and "mouseLeft" signals (emitted in my reimplementations of enterEvent and leaveEvent). This works, but:

  • The margins between the rows don't trigger the signals
  • The space on the left of the (right-aligned) labels doesn't trigger the signal
  • The widgets on the right don't trigger the signal because I haven't bothered to subclass all of them

What's the Qt-blessed approach to this kind of problem?

Some things I can think of:

  1. Make the formlayout's parent a widget that filters all mousemove events (mouse tracking?) and checks if the mouse has entered some row.
  2. Change the formlayout into a QVBoxLayout, and make the rows into some custom widget like FormRowWidget which handles both hover events and the form-alignment stuff.

Neither is very nice.

1
Tip: Add your solution as an answer and accept it if you've solved your problem by yourself.Macke

1 Answers

0
votes

I ended up using the first of the two solutions. Good enough, and with some work it can be isolated into a reusable subclass of QFormLayout.