Value from combo box to LCD
Trying to understand signals and slots.
Have looked at many examples, but can not find how to incorporate them into my working program.
The following code is meant to take a changed value from a combo box, and enter it in an LCD.
The program runs without error, but the LCD is not activated.
What do I have to change to get it to work?
Thanks,
Don
Code:
def createTopRightGroupBox(self):
self.
topRightGroupBox = QtGui.
QGroupBox("Top Right")
labelVolts
= QtGui.
QLabel("Volts/Div") labelVolts.setAlignment(QtCore.Qt.AlignHCenter)
volts = ['2.5', '5.0', '10.0', '20.0']
comboVolts.addItems(volts)
layout.addWidget(labelVolts)
layout.addWidget(comboVolts)
layout.addWidget(lcdVolts)
layout.addStretch(1)
self.topRightGroupBox.setLayout(layout)
# process signal
self.connect(comboVolts, QtCore.SIGNAL('valueChanged'), self.changeValue)
def changeValue(self, event):
volts = self.comboVolts.value()
self.lcdVolts.display(volts)
Re: Value from combo box to LCD
I think you are missing "self" prefix when creating widgets. They don't land in the scope of your object.
Re: Value from combo box to LCD
Quote:
Originally Posted by
wysota
I think you are missing "self" prefix when creating widgets. They don't land in the scope of your object.
Thanks for your reply, but I do not understand it.
The plotting demo, from which I based mine, does not use self when creating widgets, and runs correctly.
The only thing that does not work, is my attempt to transfer a value from a combo box to an LCD.
I do not understand "land in the scope of your object". Could you explain, please?
Thanks,
Don
Re: Value from combo box to LCD
In "changeValue" you refer to some object "self.lcdVolts" but where is that object? I don't see you assigning anything to "self.lcdVolts" anywhere. "self.lcdVolts" and "lcdVolts" are two totally different objects.
Re: Value from combo box to LCD
Quote:
Originally Posted by
wysota
In "changeValue" you refer to some object "self.lcdVolts" but where is that object? I don't see you assigning anything to "self.lcdVolts" anywhere. "self.lcdVolts" and "lcdVolts" are two totally different objects.
Well, I added "self" to all places where it seemed appropriate. The program runs fine with, or without, "self", but the value is still not transferred to the LCD.
I'm still missing something, but can't figure out what.
Thanks for your patience,
Don
Code:
def createTopRightGroupBox(self):
self.
topRightGroupBox = QtGui.
QGroupBox("Top Right")
self.
labelVolts = QtGui.
QLabel("Volts/Div") self.labelVolts.setAlignment(QtCore.Qt.AlignHCenter)
volts = ['2.5', '5.0', '10.0', '20.0']
self.comboVolts.addItems(volts)
layout.addWidget(self.labelVolts)
layout.addWidget(self.comboVolts)
layout.addWidget(self.lcdVolts)
layout.addStretch(1)
self.topRightGroupBox.setLayout(layout)
# process signal
self.connect(self.comboVolts, QtCore.SIGNAL('valueChanged(double)'), self.changeValue)
def changeValue(self, event):
volts = self.comboVolts.value()
self.lcdVolts.display(volts)