python - PyQt: QListView in connection with QTexEdit -


i have qlistview , qtextedit on form , them working together, follows: if checkbox checked, index of respective item in qlistview should displayed in tbe qtextedit; if checkbox unchecked, value should deleted qtextedit. indexes should displayed cumulatively, delimited 1 character (say, comma), eg., 0,1,3.

conversely, if value typed in the qtextedit, respective checkbox should automatically checked (or none, in case value entered not correspond index in qlistview).

i attempted catch indices of selected checboxes attaching handler clicked event of qlistview, below:

<del>@qtcore.pyqtslot(qtcore.qmodelindex)     def onclick(self, index):         editbox.settext(str(index.row()))</del> 

but got error message: "nameerror: global name 'self' not defined".

any hints? in advance assistance can provide!

here complete test code:

edit: changed code below deal event handlers.

import sys pyqt4 import qt, qtcore, qtgui  class mainwindow(qtgui.qwidget):     def __init__(self):         qtgui.qwidget.__init__(self)          model = qtgui.qstandarditemmodel()         n in range(10):                                item = qtgui.qstandarditem('item %s' % n)             item.setcheckstate(qtcore.qt.unchecked)             item.setcheckable(true)             model.appendrow(item)          listview = qtgui.qlistview()         listview.setmodel(model)         listview.clicked.connect(self.onclick)          self.editbox = qtgui.qtextedit()         self.editbox.textchanged.connect(self.onchange)          grid = qtgui.qgridlayout()         grid.setrowstretch(0, 6)         grid.setrowstretch(1, 4)         grid.addwidget(listview)         grid.setspacing(2)         grid.addwidget(self.editbox)          self.setlayout(grid)         self.setgeometry(300, 150, 350, 300)         self.setwindowtitle("example")         self.show()      #@qtcore.pyqtslot(qtcore.qmodelindex)     def onclick(self, index):         self.editbox.append(str(index.row()))      def onchange(self):         print "text in edit box changed"  if __name__ == '__main__':     app = qtgui.qapplication(sys.argv)     mw = mainwindow()     sys.exit(app.exec_()) 

since you're defining onclick outside of class definition, there's no self (which refers instance of class) either. define regular function instead:

@qtcore.pyqtslot(qtcore.qmodelindex) def onclick(index):     editbox.settext(str(index.row())) 

and connect signal listview.clicked.connect(onclick).


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -