允许一个文本框验证点

时间:2018-04-02 17:41:05

标签: c#

我需要只允许一个句号和逗号后面的数字。重点和逗号 他们不能一个人去,因为它是一个要验证的领域。它只能输入一个 数 还有一个逗号。 这是我在按键事件中的代码。

class App4(QtGui.QMainWindow, design4.Ui_MainWindow):
    def __init__(self, parent =None):

        super(self.__class__, self).__init__()
        self.setupUi(self)

        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.outputClicked)
        self.timer.setInterval(250)

        self.sendFlow.clicked.connect(self.inputClicked)
        self.displayFlow.clicked.connect(self.timer.start)
        self.hfButton.clicked.connect(self.heatFluxRead)

    def inputClicked(self):

        air = float(self.AirFlowInput.text())
        propane = self.PropaneFlowInput.text()

        if air <= 160 and air > 0:
            acv = air / 20.0 / n *2 +.05#compute air control voltage for each controller
            DAQC2.setDAC(0,0,acv) #changing voltage signal for channel 0
            DAQC2.setDAC(0,1,acv)
        else:
            DAQC2.setDAC(0,0,0)

        print DAQC2.getDAC(0,1)
        print DAQC2.getDAC(0,0)

    def outputClicked(self):

        airRead = float(DAQC2.getADC(0,0)-.01) * 40 / n #converting 0-4Volts to flow
        self.airFlowMeasured.display(airRead)


        #print DAQC2.getADC(0,0)

        #propRead = float(DAQC2.getADC(0,2)-.01) * 20
        #self.propaneFlowMeasured.display(propRead)


        #print DAQC2.getADC(0,1)

        #palette = self.airFlowMeasured.palette()
        #role = self.airFlowMeasured.backgroundRole()
        #if float(DAQC2.getADC(0,0)) < (air*(1-tolerance):
         #                            palette.setColor(role, QColor('yellow'))
        #else if

    def heatFluxRead(self):

        heatFlux = float(DAQC2.getADC(0,7)) * 5800.0 #converts volts to kW/m^2
        self.hfNumber.display(heatFlux)

        print heatFlux
        print self.getADC2(0,7)

    def getADC2(self,addr,channel):
        DAQC2.VerifyADDR(addr)
        DAQC2.VerifyAINchannel(channel) 
        resp= DAQC2.ppCMD(addr,0x30,channel,0,2)
        value=(256*resp[0]+resp[1])
        if (channel==8):
            value=value*5.0*2.4/65536
        else:
            value=(value*24.0/65536)-12.0
            value=round(value*DAQC2.calScale[addr][channel]+DAQC2.calOffset[addr][channel],5)
        return value

1 个答案:

答案 0 :(得分:0)

您不希望按键事件,您希望文本字段文本更改事件。

正则表达式可能对您有帮助。