Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to be notified when a row is hovered in a QFormLayout?
Qt 6.11 is out! See what's new in the release blog

How to be notified when a row is hovered in a QFormLayout?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefan Monov
    wrote on last edited by
    #1

    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:

    • Make the formlayout's parent a widget that filters all mousemove events (mouse tracking?) and checks if the mouse has entered some row.
    • 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 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      As I think the best variant is your second variant. Also you can just make QVBoxLayout of QWidgets and set to each of them FormLayout with one row. This way you will not needed to handle alignment.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Stefan Monov
        wrote on last edited by
        #3

        I would still need to handle alignment. By alignment I don't mean whether the label is left or right aligned! What I mean is the necessity to have the fields line up with each other vertically (similarly to a QGridLayout).

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          Oh yeah, haven't took it in case. Then I think that you can create additional mediator-class for align this widgets identically through this class.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mario
            wrote on last edited by
            #5

            Another solution could be to use QTreeWidget/QTableWidget, maybe?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              [quote author="mario" date="1285568589"]Another solution could be to use QTreeWidget/QTableWidget, maybe?[/quote]
              Yeah, maybe. Delegates will help author.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved