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 determine in MainWindow's mouseReleaseEvent() whether mouse is over a specific widget
Forum Updated to NodeBB v4.3 + New Features

How to determine in MainWindow's mouseReleaseEvent() whether mouse is over a specific widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 2 Posters 6.9k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi
    Enter/Leave events are not ment to be send if u are holding mouse down.
    Some widgets (like buttons) call grabMouse so they are sure to get the Release
    event so they can draw correctly.

    You can try
    http://doc.qt.io/qt-5/qapplication.html#widgetAt

    But can you tell why you need Enter event while holding mouse ?
    That is normally only needed for drag&drop operations which Qt has system for.

    NiagarerN 1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      Enter/Leave events are not ment to be send if u are holding mouse down.
      Some widgets (like buttons) call grabMouse so they are sure to get the Release
      event so they can draw correctly.

      You can try
      http://doc.qt.io/qt-5/qapplication.html#widgetAt

      But can you tell why you need Enter event while holding mouse ?
      That is normally only needed for drag&drop operations which Qt has system for.

      NiagarerN Offline
      NiagarerN Offline
      Niagarer
      wrote on last edited by Niagarer
      #3

      @mrjj
      Thanks!
      Uhm, yes I want to drag and drop something.
      I have a widget with pushButtons and when I click on such a pushButton and drag the mouse over the QGraphicsScene, I want to add a QGraphicsItem to the scene.
      Which system are you talking about? I didn't know, there is something like that, but I would completely appreciate it :D

      mrjjM 1 Reply Last reply
      0
      • NiagarerN Niagarer

        @mrjj
        Thanks!
        Uhm, yes I want to drag and drop something.
        I have a widget with pushButtons and when I click on such a pushButton and drag the mouse over the QGraphicsScene, I want to add a QGraphicsItem to the scene.
        Which system are you talking about? I didn't know, there is something like that, but I would completely appreciate it :D

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @Niagarer
        Oh the buttons grab the mouse so the Release event go back to the button you clicked on.
        You should consider using a list for the items that can be added as QPushButton will work
        against you.

        http://doc.qt.io/qt-5/dnd.html

        This one could be good base
        http://doc.qt.io/qt-5/qtwidgets-draganddrop-puzzle-example.html
        It also shows how you store your own data in the drop event so the
        QGraphicsScene can know what to add.
        Look at the PiecesList. You can easy adapt that to hold your "Drag items"
        and reuse the code to allow it to be dragged. ( same code for all cases)

        NiagarerN 2 Replies Last reply
        2
        • mrjjM mrjj

          @Niagarer
          Oh the buttons grab the mouse so the Release event go back to the button you clicked on.
          You should consider using a list for the items that can be added as QPushButton will work
          against you.

          http://doc.qt.io/qt-5/dnd.html

          This one could be good base
          http://doc.qt.io/qt-5/qtwidgets-draganddrop-puzzle-example.html
          It also shows how you store your own data in the drop event so the
          QGraphicsScene can know what to add.
          Look at the PiecesList. You can easy adapt that to hold your "Drag items"
          and reuse the code to allow it to be dragged. ( same code for all cases)

          NiagarerN Offline
          NiagarerN Offline
          Niagarer
          wrote on last edited by Niagarer
          #5

          @mrjj
          Ok, thanks I will try to solve it this way.
          Oh hell, looks complicated, this will take time, but I will update this post once Im finished.

          1 Reply Last reply
          0
          • mrjjM mrjj

            @Niagarer
            Oh the buttons grab the mouse so the Release event go back to the button you clicked on.
            You should consider using a list for the items that can be added as QPushButton will work
            against you.

            http://doc.qt.io/qt-5/dnd.html

            This one could be good base
            http://doc.qt.io/qt-5/qtwidgets-draganddrop-puzzle-example.html
            It also shows how you store your own data in the drop event so the
            QGraphicsScene can know what to add.
            Look at the PiecesList. You can easy adapt that to hold your "Drag items"
            and reuse the code to allow it to be dragged. ( same code for all cases)

            NiagarerN Offline
            NiagarerN Offline
            Niagarer
            wrote on last edited by Niagarer
            #6

            @mrjj
            Well, I took a closer look to this (to the implementation).
            And here comes the question I can't find anything about in the docs: How can I display custom widgets as items in the QListView but keeping all stuff like drag and drop usable but without using a delegate class (or is this even possible)?

            mrjjM 1 Reply Last reply
            0
            • NiagarerN Niagarer

              @mrjj
              Well, I took a closer look to this (to the implementation).
              And here comes the question I can't find anything about in the docs: How can I display custom widgets as items in the QListView but keeping all stuff like drag and drop usable but without using a delegate class (or is this even possible)?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @Niagarer

              I used images. For each custom widget, i used the render() function to make it draw a
              pixmap (thumbnail) i then used in the list.

              While you can use ListWidget and setItemWidget, it is very heavy and
              listView + delegate is recommended.
              If you only have few items and its on Desktop pc, then setItemWidget
              works ok but for many items, delegate is the way to do it.
              Alternativt, scrollarea can also be used for a list of widgets. but really depends
              on how many items u have.

              NiagarerN 1 Reply Last reply
              0
              • mrjjM mrjj

                @Niagarer

                I used images. For each custom widget, i used the render() function to make it draw a
                pixmap (thumbnail) i then used in the list.

                While you can use ListWidget and setItemWidget, it is very heavy and
                listView + delegate is recommended.
                If you only have few items and its on Desktop pc, then setItemWidget
                works ok but for many items, delegate is the way to do it.
                Alternativt, scrollarea can also be used for a list of widgets. but really depends
                on how many items u have.

                NiagarerN Offline
                NiagarerN Offline
                Niagarer
                wrote on last edited by
                #8

                @mrjj
                Ok, so using a delegate class with the ListView would be the best way, if I understood correctly.
                I unfortunately can't use jsut a thumbnail pixmap, the user should be able to interact with the widget and the widget should be able to display many things (but every item I add to the ListView would be from the same widget class, otherwise I could not use a ListView, I have read).
                Would I still have these handeling features in a ListWidget like drag and drop in the ListView? If yes, is it more easy to implement this in a ListWidget or does it not really make a difference?

                mrjjM 1 Reply Last reply
                0
                • NiagarerN Niagarer

                  @mrjj
                  Ok, so using a delegate class with the ListView would be the best way, if I understood correctly.
                  I unfortunately can't use jsut a thumbnail pixmap, the user should be able to interact with the widget and the widget should be able to display many things (but every item I add to the ListView would be from the same widget class, otherwise I could not use a ListView, I have read).
                  Would I still have these handeling features in a ListWidget like drag and drop in the ListView? If yes, is it more easy to implement this in a ListWidget or does it not really make a difference?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @Niagarer
                  It will have drag & drop support but its ment for the normal items and if u have full blown
                  widgets instead, you will need to add support for those.
                  The delegate must be able to draw (in code) the looks of the real widget so
                  if its complex widgets, it will be tons of work.
                  But yes it could work.

                  How many of these custom widgets are we talking about?

                  NiagarerN 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Niagarer
                    It will have drag & drop support but its ment for the normal items and if u have full blown
                    widgets instead, you will need to add support for those.
                    The delegate must be able to draw (in code) the looks of the real widget so
                    if its complex widgets, it will be tons of work.
                    But yes it could work.

                    How many of these custom widgets are we talking about?

                    NiagarerN Offline
                    NiagarerN Offline
                    Niagarer
                    wrote on last edited by Niagarer
                    #10

                    @mrjj
                    If I'm unlucky, one day it could go to a thousand.
                    So I should not use a ListWidget if I understood correctly, but a ListView will be tons of work...
                    :/
                    I thought, this would not be such a big problem >.<

                    mrjjM 1 Reply Last reply
                    0
                    • NiagarerN Niagarer

                      @mrjj
                      If I'm unlucky, one day it could go to a thousand.
                      So I should not use a ListWidget if I understood correctly, but a ListView will be tons of work...
                      :/
                      I thought, this would not be such a big problem >.<

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @Niagarer
                      Then both setItemWidget and ScrolLArea will potentially be very slow.
                      Depending on the hardware it must run on. The memory alone will be high.

                      Are all those different ?

                      NiagarerN 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @Niagarer
                        Then both setItemWidget and ScrolLArea will potentially be very slow.
                        Depending on the hardware it must run on. The memory alone will be high.

                        Are all those different ?

                        NiagarerN Offline
                        NiagarerN Offline
                        Niagarer
                        wrote on last edited by Niagarer
                        #12

                        @mrjj
                        Well the widget objects will come from the same class. What I mean is that I display only widget objects from f.e. MyWidget-class but with different text shown, and a different icon and some more different icons I will add to the widgets in the MyWidget-class, but the class is just one. (Actually I wanted to make two different ones for a QTreeWidget, but I guess I sould avoid that, it seems to be hard...)
                        Yes, actually I wanted to make it runnable on very slow hardware

                        mrjjM 1 Reply Last reply
                        0
                        • NiagarerN Niagarer

                          @mrjj
                          Well the widget objects will come from the same class. What I mean is that I display only widget objects from f.e. MyWidget-class but with different text shown, and a different icon and some more different icons I will add to the widgets in the MyWidget-class, but the class is just one. (Actually I wanted to make two different ones for a QTreeWidget, but I guess I sould avoid that, it seems to be hard...)
                          Yes, actually I wanted to make it runnable on very slow hardware

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @Niagarer
                          Then no doubt you should use a delegate.
                          Also since its only the data that changes, then it wont be so much work
                          as if many different widgets.

                          1 Reply Last reply
                          0
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            Do you have a picture of what you want ?

                            NiagarerN 2 Replies Last reply
                            0
                            • mrjjM mrjj

                              Do you have a picture of what you want ?

                              NiagarerN Offline
                              NiagarerN Offline
                              Niagarer
                              wrote on last edited by Niagarer
                              #15

                              @mrjj
                              Well actually yes, give me a minute, the engine has to start...

                              1 Reply Last reply
                              1
                              • mrjjM mrjj

                                Do you have a picture of what you want ?

                                NiagarerN Offline
                                NiagarerN Offline
                                Niagarer
                                wrote on last edited by Niagarer
                                #16

                                @mrjj
                                In the end I would really like to have something like this:
                                0_1509394698450_Qt 19.png
                                With the List I want only to represent the content inside the green rect.
                                I think I will not need the tree structure, only these widgets with f.e. this f, because once this list gets very big, only the search function will be used anymore (but if it is completele a joke to implement it with a treeList after I get it work with the ListView, I would appreciate it). But I would like to add some more little icons like that at the right side of the widget.

                                mrjjM 1 Reply Last reply
                                0
                                • NiagarerN Niagarer

                                  @mrjj
                                  In the end I would really like to have something like this:
                                  0_1509394698450_Qt 19.png
                                  With the List I want only to represent the content inside the green rect.
                                  I think I will not need the tree structure, only these widgets with f.e. this f, because once this list gets very big, only the search function will be used anymore (but if it is completele a joke to implement it with a treeList after I get it work with the ListView, I would appreciate it). But I would like to add some more little icons like that at the right side of the widget.

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #17

                                  @Niagarer
                                  So its like a text line with some icons ?

                                  What is the "Get BlackBoard thing ?"

                                  NiagarerN 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @Niagarer
                                    So its like a text line with some icons ?

                                    What is the "Get BlackBoard thing ?"

                                    NiagarerN Offline
                                    NiagarerN Offline
                                    Niagarer
                                    wrote on last edited by Niagarer
                                    #18

                                    @mrjj
                                    Thats a tooltip, the mouse was over the Get Blackboard thing and on the left of the widget there is also shown a little pushButton (the little star) to mark it as favourite (because the mouse was over this component).

                                    mrjjM 1 Reply Last reply
                                    0
                                    • NiagarerN Niagarer

                                      @mrjj
                                      Thats a tooltip, the mouse was over the Get Blackboard thing and on the left of the widget there is also shown a little pushButton (the little star) to mark it as favourite (because the mouse was over this component).

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #19

                                      @Niagarer

                                      Ok. i think a delegate will work super since its relatively simple structure.
                                      We often refer to
                                      http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html
                                      for delegate sample

                                      NiagarerN 1 Reply Last reply
                                      1
                                      • mrjjM mrjj

                                        @Niagarer

                                        Ok. i think a delegate will work super since its relatively simple structure.
                                        We often refer to
                                        http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html
                                        for delegate sample

                                        NiagarerN Offline
                                        NiagarerN Offline
                                        Niagarer
                                        wrote on last edited by Niagarer
                                        #20

                                        @mrjj
                                        In the example, a QTableWidget is used. And so it has no model (no QAbstractItemModel, the struct is actually the model). Would all this also work with QListViews or QTableViews?

                                        mrjjM 1 Reply Last reply
                                        0
                                        • NiagarerN Niagarer

                                          @mrjj
                                          In the example, a QTableWidget is used. And so it has no model (no QAbstractItemModel, the struct is actually the model). Would all this also work with QListViews or QTableViews?

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #21

                                          @Niagarer
                                          Yes the delegate is the same regardless of the view/widget used.
                                          http://doc.qt.io/qt-5/model-view-programming.html

                                          The delegate can be seen as way to custom paint.

                                          1 Reply Last reply
                                          1

                                          • Login

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