Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PyQt4.x Python 2.7 + QGraphicview with custom widget, move position with mouse
Forum Updated to NodeBB v4.3 + New Features

PyQt4.x Python 2.7 + QGraphicview with custom widget, move position with mouse

Scheduled Pinned Locked Moved Unsolved Language Bindings
6 Posts 2 Posters 2.5k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by Dariusz
    #1

    Hey

    Hope this is the right place.

    I have added a QGroupBox to QGraphicview via:

    self.Scene = QGraphicsScene()
    ab = CustomGroupBox() # Subclassed
    self.Scene.addWidget(ab)
    

    I then subclassed the QGroupBox with hoping that I can override

    mouseMoveEvent()
    

    With something like this :

    def mouseMoveEvent(self, event):
        super(CustomGroupBox, self).mouseMoveEvent(event)
        print event
        p = QtGui.QCursor.pos()
        pos_wid =  self.mapToGlobal(self.pos())
        self.move(p.x(),p.y())
    

    So that I can move the widget around in the scene. However every time I click and start dragging the widget jumps by xx pixels right/left anywhere depending where the window is. I know is an issue of positioning I just don't know how to solve it :- (.

    Any help would be amazing!
    Regards
    Dariusz

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      IIRC, that's already handled by the Graphics View Framework. Take a look at the GraphicsItemFlag and setFlag.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by Dariusz
        #3

        Hey

        Mmmm I'm lost... where do you want me to set the flag up ?

        I tried setting it up on my custom widget but that does nothing as far as I can tell.. When I disabled my mouseMoveEvent and just let ur flags I could not move icons at all...

        Here is video of the issues : https://vid.me/hwaa
        Here is most of my custom widget:

        class CustomGroupBox(QGroupBox):
            def __init__(self, parent=None):
                super(CustomGroupBox, self).__init__(parent)
        def mouseMoveEvent(self, event):
                super(CustomGroupBox, self).mouseMoveEvent(event)
                p = QtGui.QCursor.pos()
                self.move(p.x(),p.y())
        
        

        I think what I need is to somehow remap my mouse position to graphic view position and then on top of that offset widget position to mouse... but no idea how :- (

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          On the item returned by self.Scene.addWidget(ab)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dariusz
            wrote on last edited by Dariusz
            #5

            Hey

            Humh I must be missing something... when I tried :

                    ab = QGroupBox()
                    ab.setFixedWidth(200)
                    xx = QGridLayout()
                    wa = QPushButton("wow")
                    xx.addWidget(wa)
                    wa.clicked.connect(self.printWiw)
                    ab.setLayout(xx)
                    ab.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
                    self.Scene.addWidget(ab)
            

            I got :

            ab.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
            AttributeError: 'QGroupBox' object has no attribute 'setFlag'
            

            When I tried to add it after scene :

            for items in self.Scene.items():
            items.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
            

            The item groupbox is still unmovable.

            Edit:
            Also tried:

            for items in self.Scene.items():
                        items.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)
                        items.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True)
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              This stackoverflow answer might give you some clues.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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