【问题标题】:sending a parameter by button press with QPushButton使用 QPushButton 按下按钮发送参数
【发布时间】:2014-01-08 18:07:46
【问题描述】:

我有一个带有一个 QLabel、一个 QLineEdit 和一个 QPushButton“查找”的 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

【问题讨论】:

    标签: python qt pyqt signals-slots qpushbutton


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2022-12-03
      • 1970-01-01
      • 2015-03-04
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2021-01-08
      • 1970-01-01
      相关资源
      最近更新 更多