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. Issues trying to disable dragging of the buttons
Forum Updated to NodeBB v4.3 + New Features

Issues trying to disable dragging of the buttons

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 741 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.
  • ConfusedProgrammerC Offline
    ConfusedProgrammerC Offline
    ConfusedProgrammer
    wrote on last edited by ConfusedProgrammer
    #1

    Hello everybody,

    I made a Button class that inherits QGraphicsRectItem in order to have the button to be draggable accross the view. A button object is the added to a scene and it allows me to drag the buttons just like I want.

    My problem is that I want to be able to disable the dragging from a menu action item.

    I tried to make a method on the button class that will simply toggle the flag : self.setFlag(QGraphicsItem.ItemIsMovable, False)

    However when I use the method when I stored the objects in a list it results with this error.

    AttributeError: 'NoneType' object has no attribute 'disable_dragbuttons'

    Could anybody point me in the right direction?

    Something to consider I am using Python with PySide2.

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

      Hi,

      Can you show how you create these buttons and how to you put them it that list ?

      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
      • ConfusedProgrammerC Offline
        ConfusedProgrammerC Offline
        ConfusedProgrammer
        wrote on last edited by
        #3

        Yes I will, I am using python though. Here is the code.

        class Button(QGraphicsRectItem):
            def __init__(self, text, *args): 
                 QGraphicsRectItem.__init__(self, *args)
                 #allows buttons to be dragged
                 self.setFlag(QGraphicsItem.ItemIsMovable, True)
        
              def disable_button_drag(self):
                    self.setFlag(QGraphicsItem.ItemIsMovable, True)  #disable dragging
           
        
        #Adding 10 buttons to list and at scene 
        def load_buttons(self):
              self.buttons = [self.scene.addItem(Button("name",coords)) for i in range(10)]
        

        This results in 10 buttons drawn at the QGraphicsView and are draggable. Issue is that I cant modify the buttons afterward because of the Nonetype error.

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

          What do you get if you print(self.buttons) after calling load_buttons ?

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

          ConfusedProgrammerC 1 Reply Last reply
          0
          • SGaistS SGaist

            What do you get if you print(self.buttons) after calling load_buttons ?

            ConfusedProgrammerC Offline
            ConfusedProgrammerC Offline
            ConfusedProgrammer
            wrote on last edited by
            #5

            @SGaist

            Hi I get a NoneType.

            I found the issue turns out that I am calling a method inside that array. <doh!>

            I did this now and it works.

            def load_buttons(self):
               self.buttons = [Button(name,coords) for i in range(10)]
               
               for button in buttons:
                      self.scene.addItem(button)
                      print(button)
            
            

            Now instead of printing None it now prints an object address.

            After doing this the buttons now work as intended.

            Thank you guys, you are really good.

            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