I have a new QLineEdit(box) for the subject code.Each subject has a subject code(for eg Sentiment Analysis has code CS01,Data Cleansing has CS02,etc.).When i select one subject(Sentiment Analysis) its subject code(CS01) should be displayed in the new edit box and when i choose another subject(Data CLeansing) its subject code(CS02) should be dispalyed .How should the problem be solved?
import sys
from PyQt4 import QtGui, QtCore
class MyWindow(QtGui.QWidget):
def __init__(self, parent = None):
super(MyWindow, self).__init__(parent)
self.setGeometry(50, 50, 350,350)
QtGui.QShortcut(QtGui.QKeySequence("Esc"), self, self.close)
# Create controls
self.lbl = QtGui.QLabel('Types of Analysis', self)
self.lbl.setFont(QtGui.QFont('SansSerif', 15) )
self.cb = QtGui.QComboBox(self)
self.cb.addItems(['Sentiment Analysis', 'Data Cleansing', 'Genomics', 'Integration', 'Visualization'])
self.btn = QtGui.QPushButton('Submit', self)
self.b=QtGui.QLineEdit(self)
self.b.move(50,130)
self.cb.currentIndexChanged[str].connect(self.b.setText)
self.b1=QtGui.QLineEdit(self)
self.b1.move(50,180)
# Create layout
mainLayout = QtGui.QVBoxLayout()
mainLayout.addWidget(self.lbl)
mainLayout.addWidget(self.cb)
mainLayout.addWidget(self.b)
mainLayout.addWidget(self.b1)
mainLayout.addWidget(self.btn)
self.setLayout(mainLayout)
self.btn.clicked.connect(self.printingaction)
self.show()
def printingaction(self):
print 'Current item: {0}'.format( self.cb.currentIndex() ) # ComboBox's index
print 'Current index: {0}'.format( self.cb.currentText() ) # ComboBox's text
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
win = MyWindow()
sys.exit( app.exec_() )