I created a Main window with 2 button by pyqt5 and now i want to add a combo box to it. But if i keep App(QMainWindow), the combo box wont show. Only if i write App(QWidgets) it will show. Are there any way to add a combo box to main window ? here is my code:
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'Phan mem quan ly tai lieu- Tuan tien mom'
self.left = 200
self.top = 200
self.width = 320
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
button = QPushButton('chaychuongtrinh', self)
button.setToolTip('bam vao nut nay de chay chuong trinh')
button.move(100, 70)
button.clicked.connect(self.on_click)
button1 = QPushButton('kiemtra', self)
button1.setToolTip('kiem tra thong tin')
button1.move(200, 70)
button1.clicked.connect(self.on_click)
layout = QHBoxLayout()
self.cb = QComboBox()
self.cb.addItem("C")
self.cb.addItem("C++")
self.cb.addItems(["Java", "C#", "Python"])
self.cb.currentIndexChanged.connect(self.selectionchange)
layout.addWidget(self.cb)
self.setLayout(layout)
self.setWindowTitle("combo box demo")
self.show()
def selectionchange(self,i):
print ("Items in the list are :")
print(self.cb.currentText())