2013-12-20 73 views
2

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

# 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的文本?

回答

1

可以使用lambda发送查找文本,像这样:

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