PyQt QLineEdit DropEvent无法拖入文件
本帖最后由 realhuhu 于 2021-2-7 12:27 编辑从pycharm可以正常拖入文件获得路径,但是其他地方的文件就不行了,怎么破
代码:
import sys
from PyQt5.QtWidgets import QApplication, QLineEdit
class MyQLine(QLineEdit):
def __init__(self):
super().__init__()
self.setAcceptDrops(True)
def dropEvent(self, e):
path = e.mimeData().text()
self.setText(path)
if __name__ == "__main__":
app = QApplication(sys.argv)
myWin = MyQLine()
myWin.show()
sys.exit(app.exec_()) 本帖最后由 hrp 于 2021-2-7 12:46 编辑
试试多重写一个dragEnterEvent方法,看看这个
https://fishc.com.cn/forum.php?mod=viewthread&tid=187937 hrp 发表于 2021-2-7 12:44
试试多重写一个dragEnterEvent方法,看看这个
https://fishc.com.cn/forum.php?mod=viewthread&tid=187937
不行啊 realhuhu 发表于 2021-2-7 18:51
不行啊
import sys
from PyQt5.QtWidgets import QApplication, QLineEdit
class MyQLine(QLineEdit):
def __init__(self):
super().__init__()
def dragEnterEvent(self, e):
e.accept()
def dropEvent(self, e):
path = e.mimeData().text()
self.setText(path)
if __name__ == "__main__":
app = QApplication(sys.argv)
myWin = MyQLine()
myWin.show()
sys.exit(app.exec_())
hrp 发表于 2021-2-7 22:28
还是只有pycharm里的文件才能拖进去{:10_266:} realhuhu 发表于 2021-2-8 11:57
还是只有pycharm里的文件才能拖进去
没办法了,毕竟你问题描述太模糊了。
我运行正常。 hrp 发表于 2021-2-8 13:13
没办法了,毕竟你问题描述太模糊了。
我运行正常。
可能跟环境有关,头疼
页:
[1]