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. Mouse events without own class
Forum Updated to NodeBB v4.3 + New Features

Mouse events without own class

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.7k 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.
  • W Offline
    W Offline
    Wurstinator
    wrote on 16 Sept 2012, 12:21 last edited by
    #1

    Hello,
    I have a subclass of QMainWindow and several standard widgets "inside".
    When the user right clicks somewhere, a menu with simple operations like "cut", "copy" and "paste" should pop up. My issue with this is, that the lower level widgets accept all of the QMouseEvents so that my subclass of QMainWindow never gets to see any of them.
    The only solution I could think of, would be to create my own class for every kind of widget I use and overwrite their mousePressEvent functions. That would be quite uncomfortable though and I feel like Qt probably offers a better way for this, since it looks like a rather common thing to me.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on 16 Sept 2012, 14:49 last edited by
      #2

      Three possible solutions:
      don't use the QMainWindow to pop up a context menu but use the proper Qt mechanisms:

      • by creating a custom context menu (and setting the context menu policy accordingly). React to the customContextMenuRequested signal and pop up that menu
      • or by creating QAction(s) for the widgets and set context menu policy accordingly to use the actions as menu items

      Have QMainWindow handle events centrally:

      • by installing an event filter which achieves what you initially wanted: steal events from subwidgets before they get to them.
      1 Reply Last reply
      0
      • W Offline
        W Offline
        Wurstinator
        wrote on 16 Sept 2012, 15:35 last edited by
        #3

        What do you mean by "proper mechanism"?
        So to use Qt "properly", I would have to create a subclass for every widget? Sounds a bit excessive to me. Or did I misunderstand you?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on 16 Sept 2012, 20:06 last edited by
          #4

          You did misunderstand me. The "proper" refers to the way of creating a popup menu and showing it. For example with multiple QAction and the appropriate context menu policy.
          The not so proper way is what you suggested, hacking the event system to intercept events that actually should reach the individual widgets.

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Wurstinator
            wrote on 22 Sept 2012, 19:03 last edited by
            #5

            Sorry for not answering for some time.

            I did it with the custom menu thing and it works just fine. Thanks for helping me out.

            1 Reply Last reply
            0

            1/5

            16 Sept 2012, 12:21

            • Login

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