【问题标题】:pyqt4 + radiobuttonpyqt4 + 单选按钮
【发布时间】:2013-02-21 14:54:09
【问题描述】:

我有 15 个定义。我有 15 个单选按钮(p1、p2、p3 .....p15)。我有 1 个 QPush 按钮。 当我想使用我的第一个 def 时,我选择“p1”单击我的 QPushButton,然后使用这个 def。为什么我需要它?因为我需要处理文本,所以我在我的 textedit 中打开一个文本,我需要处理它,但我只想使用单选按钮使用一个 def。 我该怎么做?

例如:

self.radioButton_1 = QRadioButton(self.Processing)
self.radioButton_1.setGeometry(QRect(520, 200, 50, 22))
self.radioButton_1.setObjectName(_fromUtf8("radioButton_1"))
self.radioButton_1.setText(QApplication.translate("Form", "P1", None, QApplication.UnicodeUTF8))
self.processLineButton = QPushButton(self.Processing)
self.processLineButton.setGeometry(QRect(800, 100, 100, 37))
self.processLineButton.setText(QApplication.translate("None","Process", None, QApplication.UnicodeUTF8))

   def example(exampless):     
        example = []
        for exx in exampless:
            es = re.findall("\.{3}!", exx)
            if es:
                example = example + [exx]
            #endif    
        #endfor

            self.TextProcess.setPlainText(example)       

【问题讨论】:

    标签: python qt radio-button pyqt pyqt4


    【解决方案1】:

    首先您需要找到选中的单选按钮,然后您可以运行分配给该按钮的功能,如下所示:

    for radioButton in self.findChildren(QtGui.QRadioButton):
        if radioButton.isChecked():
            radioButtonText = radioButton.text()
            print "Radio Button Selected: ", radioButtonText
            if radioButtonText == "example":
                example(args) 
    

    【讨论】:

      猜你喜欢
      • 2012-01-31
      • 2015-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多