单击按钮的PyQT值

时间:2018-12-13 11:43:37

标签: python python-3.x pyqt qgis

我是python和QT的新手。使用QGIS我有一个来自QT设计器的.UI,并希望通过单击按钮选择一个文件夹路径(该按钮名为GetPath)。选择文件夹是可行的,但是我无法将文件夹路径中的值返回给我的函数。它返回<PyQt5.QtCore.QMetaObject.Connection object at 0x0000026182969EB8>。布

UI类(由QGIS Plugin Builder预制)

from PyQt5 import uic
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QFileDialog 
from qgis.core import *
from qgis.utils import *

FORM_CLASS, _ = uic.loadUiType(os.path.join(
    os.path.dirname(__file__),'..' ,'UI/newproject.ui'))


class newprojectui(QtWidgets.QDialog, FORM_CLASS):
    def __init__(self, parent=None):
        """Constructor."""
        super(newprojectui, self).__init__(parent)
        self.setupUi(self)

单击按钮

dlg = newprojectui()
folder_path = dlg.GetPath.clicked.connect(pick_new)

函数pick_new

def pick_new():
    dlg = newprojectui()
    options = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly
    folder_path = QFileDialog.getExistingDirectory(dlg,"Open Folder", options=options)
    print(folder_path) 
    return folder_path 

感谢帮助

0 个答案:

没有答案