python - How to get current value from PyQt comboBox -
i using pyqt designer , converting using pyuic4.
ui file has combobox looks this:
self.combobox = qtgui.qcombobox(self.groupbox_3) self.combobox.setgeometry(qtcore.qrect(20, 30, 81, 22)) self.combobox.setobjectname(_fromutf8("combobox")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8("")) self.combobox.additem(_fromutf8(""))
so can see, text put in combo box doesnt show in part of code, show in gui.
usually when have user selection, radio button, can check:
if self.rankle.ischecked():
i can similar things input text. trying logic combobox, want self.combobox.gettext() , return string user has selected. tried doing items on http://pyqt.sourceforge.net/docs/pyqt4/qcombobox.html cant work.
for example, code:
self.combobox.activated()
returns error message:
typeerror: native qt signal not callable
i have tried use itemdata() still receive error:
typeerror: qcombobox.itemdata(int, int role=qt.userrole): not enough arguments
i doing inside of callback, first this:
self.analyzebutton.clicked.connect(self._analyzedata)
then inside function _analyzedata trying text of current combobox item.
so, possible?
thanks
well, errors, aren't pretty self-explanatory ? :-)
from documentation linked :
void activated (int)
this default overload of signal.this signal sent when user chooses item in combobox. item's index passed. note signal sent when choice not changed. if need know when choice changes, use signal currentindexchanged().
as qt signal cannot directly called: can emitted, , can create slot called when happens.
qvariant qcombobox.itemdata (self, int index, int role = qt.userrole)
returns data given role in given index in combobox, or qvariant.invalid if there no data role.
see setitemdata().
the role parameter has default value can omit it, have give index.
glad found solution anyway !
Comments
Post a Comment