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. [Moved] Drag/Drop from ListWidget to GraphicsView
Forum Updated to NodeBB v4.3 + New Features

[Moved] Drag/Drop from ListWidget to GraphicsView

Scheduled Pinned Locked Moved Language Bindings
1 Posts 1 Posters 2.2k 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
    drumboy354
    wrote on last edited by
    #1

    Hello! I'm having troubles getting the drag/drop functionality to work between a listwidget and a qgraphicsview. I can not, for the life of me, figure out how to get the qgrahicsview to show the icon when I drop it into the window. I first actually designed the layout with QT Designer. So gui_from_designer is just the python file that was translated from the ".ui" file. My code is fairly simple:

    @from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    from gui_from_designer import Ui_MainWindow@

    @class mainWindow(QMainWindow, Ui_MainWindow):

    def __init__(self, parent = None):
        super(mainWindow, self).__init__(parent)
        self.setupUi(self)
    
     self.nodeWindow.setAcceptDrops(True)
    
    #populate listwidget with icons
    path = os.path.dirname(sys.argv[0])
        for image in sorted(os.listdir(os.path.join(path, "images"))):
            if image.endswith(".png"):
                item = QListWidgetItem(image.split(".")[0].capitalize())
                item.setIcon(QIcon(os.path.join(path,
                                   "images/{}".format(image))))
                self.listWidget.addItem(item)
    
    def dragEnterEvent(self, event):
        event.accept()
    
    def dropEvent(self, event):
        event.accept()
    
    def dragMoveEvent(self, event):
        event.accept()
    

    app = QApplication(sys.argv)
    form = mainWindow()
    form.show()
    app.exec_()@

    My qgraphicsview window is called nodeWindow. I figured maybe instead of:

    @def dragEnterEvent(self, event):
    event.accept()@

    I would change all the event.accept to self.nodeWindow.event.accept():

    @def dragEnterEvent(self, event):
    self.nodeWindow.event.accept()@

    But with no luck. I'm still fairly new to PyQt and the way drag/drop works with QGraphicsView so any input would be greatly, greatly appreciated! Thanks so much!

    edit: Fixed formatting for the code!

    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