Qcombobox everytime i choose a name it prints all the name i have on my database this is my code
-
self.query = QSqlQuery("SELECT name FROM test_table")
self.comboBox = QComboBox(self)
self.comboBox.currentIndexChanged.connect(self.selectionchange)
#
while(self.query.next()):
self.comboBox.addItem(self.query.value(0).toString())
#
self.show()
def selectionchange(self):
for count in range(self.comboBox.count()):
print self.comboBox.itemText(count)i want to display only the name i choose how to do it?
-
@Gelo Use currentIndexChanged signal and donot use the loop.
-
@Gelo Use currentIndexChanged signal and donot use the loop.
@p3c0 how will i write it?
-
@Gelo Use currentIndexChanged signal and donot use the loop.
@p3c0 What loop? the while or for?
-
@Gelo Check this example:
https://www.tutorialspoint.com/pyqt/pyqt_signals_and_slots.htmIn the similar way you connect to the
currentIndexChanged
signal and get the selected index text in the connected slot. -
@p3c0 What loop? the while or for?
@Gelo said in Qcombobox everytime i choose a name it prints all the name i have on my database this is my code:
@p3c0 What loop? the while or for?
for
-
@Gelo said in Qcombobox everytime i choose a name it prints all the name i have on my database this is my code:
@p3c0 What loop? the while or for?
for
@p3c0 i am confused help me with the code please
-
@Gelo Sure but first you must become familiar with Qt's Signals and slots mechanism.
-
@Gelo Sure but first you must become familiar with Qt's Signals and slots mechanism.
@p3c0 thank you for the thread
how to convert this into a stringself.query = QSqlQuery("SELECT name FROM test_table")
self.comboBox = QComboBox(self)
self.comboBox.currentIndexChanged.connect(self.selectionchange)
#
while(self.query.next()):
self.comboBox.addItem(self.query.value(0).toString())# self.show() def selectionchange(self): print self.comboBox # i want to convert this into a string?
-
@Gelo Sure but first you must become familiar with Qt's Signals and slots mechanism.
@p3c0 Thank you again so much! i figured it out ! by just adding
def selectionchange(self):
print self.comboBox.currentText()it prints what i want!
Thank you!
-
@Gelo Great!
-
@p3c0 Thank you so much! i really appreciate your effort GodBless you !
-
@Gelo Thank You!. I need it :)