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. QGraphicsItem's child item doesn't read the drag events

QGraphicsItem's child item doesn't read the drag events

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 2.4k Views
  • 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.
  • GofferG Offline
    GofferG Offline
    Goffer
    wrote on last edited by
    #1

    Hello guys,

    I've a QGraphicsItem, that has an other one parent to it.
    Nothing fancy, none of the drag events on the child are detected, it moves the parent item instead.

    Is there a way to say that this child item doesn't affect the parent ?

    Thank you !

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).

      http://doc.qt.io/qt-4.8/qgraphicsitem.html#dragEnterEvent

      1 Reply Last reply
      0
      • GofferG Offline
        GofferG Offline
        Goffer
        wrote on last edited by
        #3

        This doesn't change anything,
        still can't see my prints inside my drag methods. The parent is still moving.

        A 1 Reply Last reply
        0
        • GofferG Goffer

          This doesn't change anything,
          still can't see my prints inside my drag methods. The parent is still moving.

          A Offline
          A Offline
          alex_malyu
          wrote on last edited by
          #4

          @Goffer

          I think the key is documentation statement:
          "By accepting the event, (i.e., by calling QEvent::accept(),) the item will accept drop events, in addition to receiving drag move and drag leave. Otherwise the event will be ignored and propagate to the item beneath."

          What I am sure about - I had implemented 2D "shape" editor myself and I had something you described and had no problem to separate child transformation from parent.

          Without seen the code it is tough to provide more than general help..

          1 Reply Last reply
          0
          • GofferG Offline
            GofferG Offline
            Goffer
            wrote on last edited by Goffer
            #5
            class HandleItem(QtWidgets.QGraphicsItem):
            
                def __init__(self, parent):
                    super(HandleItem, self).__init__(parent)
            
                    self.setAcceptDrops(True)
                    self.setAcceptHoverEvents(True)
            
            # + bounding rect()
            # + shape()
            # + paint()
            # + extra code
            
                def dragEnterEvent(self, event):
                    event.accept()
                    print 'resize start'
            

            This item is simply parent under an other one

            ...
            handleInst = HandleItem(parent=self)
            
            A 1 Reply Last reply
            0
            • GofferG Goffer
              class HandleItem(QtWidgets.QGraphicsItem):
              
                  def __init__(self, parent):
                      super(HandleItem, self).__init__(parent)
              
                      self.setAcceptDrops(True)
                      self.setAcceptHoverEvents(True)
              
              # + bounding rect()
              # + shape()
              # + paint()
              # + extra code
              
                  def dragEnterEvent(self, event):
                      event.accept()
                      print 'resize start'
              

              This item is simply parent under an other one

              ...
              handleInst = HandleItem(parent=self)
              
              A Offline
              A Offline
              alex_malyu
              wrote on last edited by
              #6

              @Goffer

              Is parent above child?
              If not I am out of guesses. In C++ it used to work.

              1 Reply Last reply
              0
              • GofferG Offline
                GofferG Offline
                Goffer
                wrote on last edited by
                #7

                what do you mean by "Is parent above child?" ?

                A 1 Reply Last reply
                0
                • GofferG Goffer

                  what do you mean by "Is parent above child?" ?

                  A Offline
                  A Offline
                  alex_malyu
                  wrote on last edited by
                  #8

                  @Goffer I mean ZValue, but if I recall right this affect only siblings.
                  The only other guess I can make - problem might be related to wrong shape or bounding rectangle definition. Basically item is not found when clicked.

                  1 Reply Last reply
                  0
                  • GofferG Offline
                    GofferG Offline
                    Goffer
                    wrote on last edited by Goffer
                    #9

                    Well I think Z value is parent Z value + 1 when you parent unless you modify it (I didn't).
                    The shape is correct as my cursor changes when I hover it and my mousePressEvent is working perfectly.

                    This is very odd. Will keep investigasting

                    1 Reply Last reply
                    0
                    • GofferG Offline
                      GofferG Offline
                      Goffer
                      wrote on last edited by
                      #10

                      looking at some older codes, it seems that i already had the same problem and then used regular mousePress/Move/Release events with conditions.

                      might just do the same while looking for a better solution.

                      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