【发布时间】:2018-11-25 00:28:37
【问题描述】:
我对 Python 中的 Qt 很陌生,我需要知道如何从文件对话框中获取一个目录路径并将其显示在我的 ui 内的文本框中。
class ControllerLibraryUI(QtWidgets.QDialog):
def __init__(self):
super(ControllerLibraryUI, self).__init__()
self.setWindowTitle('Controller Window')
self.buildUI()
def buildUI(self):
layout = QtWidgets.QVBoxLayout(self)
textWidget = QtWidgets.QWidget()
textLayout = QtWidgets.QHBoxLayout(textWidget)
layout.addWidget(textWidget)
self.saveNameField = QtWidgets.QTextEdit()
textLayout.addWidget(self.saveNameField)
btnWidget = QtWidgets.QWidget()
btnLayout = QtWidgets.QHBoxLayout(btnWidget)
layout.addWidget(btnWidget)
importBtn = QtWidgets.QPushButton('Import')
importBtn.clicked.connect(self.load)
btnLayout.addWidget(importBtn)
closeBtn = QtWidgets.QPushButton('Close')
closeBtn.clicked.connect(self.close)
btnLayout.addWidget(closeBtn)
def load(self ):
filename = QtWidgets.QFileDialog.getOpenFileName()[0]
print filename
def showUI():
try:
ui.close()
except:
ui = ControllerLibraryUI()
ui.show()
return ui
ui = showUI()
这是基本概念。
【问题讨论】:
-
不,这只是问题的一部分
-
使用
self.saveNameField.append(filename)
标签: python python-2.7 pyqt maya pymel