使用PySide将文件拖到gui中

时间:2016-04-13 21:46:58

标签: python-3.x pyside

您好我想用PySide将文件(图片)拖到我的gui中,但是我无法让它工作。我无法进入dropEvent函数。我试图拖入的对象是QGraphicsView,因此过滤器无法接管整个gui,因为我想将两个图像拖入其中。

class Consumer(QMainWindow, Ui_MainWindow, QComboBox, QtGui.QWidget):


    def __init__(self, parent=None):
        self.paylod = None
        super(Consumer, self).__init__(parent)
        self.setupUi(self)
        self.chkApplyCompression.stateChanged.connect(self.makecompress)
        self.viewCarrier1.setMouseTracking(True)
        self.viewCarrier1.installEventFilter(self)
        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.viewCarrier1)

    def eventFilter(self, source, event):
        if (event.type() == QtCore.QEvent.QDropEvent and
            print('yay?')
        return QtGui.QWidget.eventFilter(self, source, event)





    def dropEvent(self, e):
        print("yay")

    def dragEnterEvent(self, *args, **kwargs):
        print("Yay!!")





if __name__ == "__main__":
    currentApp = QtGui.QApplication(sys.argv)
    currentForm = Consumer()
    currentForm.show()
    currentApp.exec_()

谢谢

0 个答案:

没有答案