views:

30

answers:

2

I want that, when I choose a checkbox the lineedit change the text, a different text per checkbox

I have something like that:

self.connect(self.form.cb_banda, QtCore.SIGNAL('stateChange(int)'),
         self.type)
self.connect(self.form.cb_tira, QtCore.SIGNAL('stateChange(int)'),
         self.type)

def type(self):
    if self.form.cb_banda.isChecked():
        self.form.le_clv.setText("B0000")
    elif self.form.cb_tira.isChecked():
        self.form.le_clv.setText("TP0000")

One conexion for checkbox, but doesn't work, I have the checkbox grouped in a GroupBox.

A: 

QCheckBox doesn't have isChecked method. Instead you have to use checkState method. Like this:

if self.form.cb_banda.checkState() == Qt.Checked:
        self.form.le_clv.setText("B0000")

Haven't you got an Exception (AttributeError I guess) about that?

gruszczy
I don't have, I don't remember where read that for non tristate checkbox I can use "isChecked".
Alquimista
I am looking at the PyQt4 reference and I can't see that. Have you tried the above code?
gruszczy
A: 

Sorry it was a typo

is stateChanged(int) not stateChange(int), now work fine and thanks for your time grusczy.

Alquimista