我有一个带有一个QLabel,一个QLineEdit和一个QPushButton“ Find”的QDialog。按下按钮后,我想将在QLineEdit中输入的文本发送到另一个函数,该函数将处理“查找”按钮的操作。

# shows and handles the find dialog
def handleFind(self):
    findDialog = QDialog()
    findDialog.setWindowTitle("Find")
    grid = QGridLayout()
    findDialog.setLayout(grid)

    findLabel = QLabel("Find what", findDialog)
    grid.addWidget(findLabel,1,0)
    findField = QLineEdit(findDialog)
    grid.addWidget(findField,1,1)
    enteredText = findLabel.text()
    findButton = QPushButton("Find", findDialog)
    # how to send enteredText as parameter to the find function
    findButton.clicked.connect(self.find)
    grid.addWidget(findButton,2,1)

    findDialog.exec_()

# find function: search in the first column of the table
def find(self):
    #to do
    names = NvmQtModel.__imp.parameterNames()


如何将在QLineEdit中输入的文本作为参数发送到函数find

最佳答案

您可以使用lambda发送查找文本,如下所示:

    findButton.clicked.connect(
        lambda: self.find(findField.text()))

关于python - 使用QPushButton通过按钮发送参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20694129/

10-09 04:10