한국어
파이썬
 

K-20140822-653622.png

 

예제 소스코드 (*.py)

import sys
from PyQt4 import QtGui, QtCore

class testDialog(QtGui.QDialog):
    def __init__(self, parent=None):
        super(testDialog, self).__init__(parent)

        form = QtGui.QFormLayout()
        form.setHorizontalSpacing(0)

        self.myedit = QtGui.QLineEdit()
        self.myedit.setDragEnabled(True)
        self.myedit.setAcceptDrops(True)
        self.myedit.installEventFilter(self)

        form.addWidget(self.myedit)

        self.setLayout(form)
        self.setGeometry(300, 300, 400, 0)
        self.setWindowTitle('drop test')

        self.myedit.textChanged.connect(self.editchange)   # new style signal slot connections

    @QtCore.pyqtSlot(str)   # int represent the column value
    def editchange(self,data):
        print "editchange:", unicode(data)

    def eventFilter(self, object, event):
        if (object is self.myedit):
            if (event.type() == QtCore.QEvent.DragEnter):
                if event.mimeData().hasUrls():
                    event.accept()   # must accept the dragEnterEvent or else the dropEvent can't occur !!!
                    print "accept"
                else:
                    event.ignore()
                    print "ignore"
            if (event.type() == QtCore.QEvent.Drop):
                if event.mimeData().hasUrls():   # if file or link is dropped
                    urlcount = len(event.mimeData().urls())  # count number of drops
                    url = event.mimeData().urls()[0]   # get first url
                    object.setText(unicode(url.toLocalFile()))   # assign first url to editline
                    #event.accept()  # doesnt appear to be needed
            return False # lets the event continue to the edit
        return False

if __name__ == "__main__":

    app = QtGui.QApplication([])
    dl = testDialog()
    dl.exec_()
    sys.exit(app.closeAllWindows())

 

번호 제목 글쓴이 날짜 조회 수
24 파이썬으로 작성된 소스를 py2exe을 이용하여 윈도우 응용프로그램 빌드시 콘솔창 숨기기 pjk 2014.07.29 7596
23 Python으로 작성된 프로그램을 윈도우응용프로그램(exe)으로 빌드하기 file pjk 2014.08.03 8095
22 [PyQt4]윈도우창에 별 찍기 예제 file pjk 2014.08.19 8141
21 다른 디렉터리의 파일(모듈) import 하기 pjk 2014.08.22 4697
» [PyQt4]폴더 또는 파일을 드레그하여 그 경로를 LineEdit로 가져오기 file pjk 2014.08.22 13544
19 [PyQt4]마우스 클릭 이벤트 예제 코드 pjk 2014.08.26 6789
18 [PyQt4]multiprocess 예제 코드 pjk 2014.08.26 8160
17 [PyQt4]스레드 및 ProgressBar 예제 코드 file pjk 2014.08.26 8264
16 Python 문자열 관련 함수 레퍼런스 pjk 2014.08.29 6645
15 [PyQt4]여러가지 버튼 예제 file pjk 2014.08.29 13747
14 [PyQt4]개발 프로그램 버전표시 메세지 박스 pjk 2014.09.02 7710
13 How to Use Freeze pjk 2014.09.06 4777
12 우분투에 Python새 버전 설치 사용법 pjk 2015.02.10 3207
11 외부 프로그램 실행 pjk 2015.02.10 15322
10 print를 로그파일로 생성하기 (log출력 Redirection) makersweb 2015.03.18 5657
9 Python + QML with PyQt4 makersweb 2015.03.24 7916
8 [pyqt4]QTimer 예제 - 버튼을 누르면 3초후 함수 또는 메소드 호출 makersweb 2015.04.01 9769
7 QML 및 Window 투명처리 file makersweb 2015.04.22 4056
6 [Python]EXE또는 DLL파일의 버전정보를 알아내기위한 몇가지 방법 makersweb 2015.06.25 8727
5 Boost Python을 이용하여 python을 위한 C++ API 바인딩 [5] file makersweb 2017.01.08 9203