【发布时间】:2017-01-06 13:27:17
【问题描述】:
我的 qt 应用程序运行一个进程并将结果保存在特定目录中。
现在用户必须前往文件夹查看结果。一般是excel文件。
我尝试过 getExistingDirectory/getOpenFileName ,它会打开 dir 路径以选择文件夹或打开文件。
我只想打开一个独立于pyqt4的文件夹。 (例如:在 windows 中按“Windows + E”快捷键。
from PyQt4 import QtGui,QtCore
import sys,os
class OpenDir(QtGui.QMainWindow):
def __init__(self):
super(OpenDir, self).__init__()
# self.openDirectory()
self.button = QtGui.QPushButton('Open', self)
self.button.clicked.connect(self.openDirectory)
self.setCentralWidget(self.button)
def openDirectory(self):
print "Hi i am openDirectory Function . I will open Directory selected "
openDirectoryDialog=QtGui.QFileDialog()
print openDirectoryDialog
# oD=openDirectoryDialog.getExistingDirectory(self,"open",os.path.abspath("..\."),openDirectoryDialog.ShowDirsOnly) #Selectes folder
# oD = openDirectoryDialog.directoryEntered(self,"open", os.path.abspath("..\."))
print oD
if len(oD) > 0:
print "accepted"
else:
print "nothing selected"
def main():
app = QtGui.QApplication(sys.argv)
ui=OpenDir()
ui.show()
sys.exit(app.exec_())
#Function Main END
if __name__ == '__main__':
main()
【问题讨论】:
-
您可能正在寻找这个问题的答案:How to “Reveal in Finder” or “Show in Explorer” with Qt。答案是 C++,但很容易适应 python。如果您只针对没有可移植性的 Windows,您可以使用此命令
C:\Windows\explorer.exe /select,<filepath>启动 explorer.exe。 -
@Neitsa:谢谢,它真的很有帮助。但我一直在 pyqt QfileDialog 或 pyqt 的任何其他模块中寻找方法。