emit dataChanged signal PyQt5 -


i not able emit datachanged signal model. under python 3.5.2, pyqt5.9.1.

i tried @ least 4 different syntaxes, none of works me: different veiws of model updated when click on them...

@pyqtslot() def setdata(self, index: qmodelindex, any, role=none):     if role == qtcore.qt.editrole:         row = index.row()         color = qtgui.qcolor(any)         if color.isvalid():             self._datas[row] = color             # self.datachanged.emit(index,index) # doesn't work because pyqt5 changed signature             # self.datachanged.emit(index, index, []) # doesn't update other views of same model             # self.datachanged.emit(index,index,[qtcore.qt.editrole,]) # neither             # self.data_changed.emit(index,index) # class method 'data_changed = pyqtsignal(qmodelindex,qmodelindex)', doesn't work              return true     return false 

this question how emit datachanged in pyqt5 marked solved, however, not able reproduce

edit: verifiable exemple, several views of same model. expecting views updated, whenever change color

edit_2 solved... typo... exemple works expected

from pyqt5 import qtgui, qtcore pyqt5 import qtwidgets pyqt5.qtwidgets import qapplication pyqt5.qtcore import qmodelindex, pyqtsignal,qabstractlistmodel, pyqtslot import sys   class listmodel(qabstractlistmodel):      def __init__(self, colors=none):         super(qabstractlistmodel, self).__init__()         self._datas = colors       def data(self, index: qmodelindex, role=none):         row = index.row()         value = self._datas[row]          if role == qtcore.qt.displayrole:             return value.name()          elif role == qtcore.qt.decorationrole:             pixmap = qtgui.qpixmap(12,12)             pixmap.fill(value)             icon = qtgui.qpixmap(pixmap)             return icon          elif role == qtcore.qt.tooltiprole:             return "hex code: " + self._datas[row].name()       def rowcount(self, parent=none, *args, **kwargs):         return len(self._datas)      def headerdata(self, p_int, qt_orientation, role=none):          if role == qtcore.qt.displayrole:              if qt_orientation == qtcore.qt.horizontal:                  return "palette"              else:                 return "color {a}".format(a=p_int)      def flags(self, qmodelindex: qmodelindex):         # check state editable or not?         return qtcore.qt.itemiseditable | qtcore.qt.itemisselectable | qtcore.qt.itemisenabled      @pyqtslot()     def setdata(self, qmodelindex, any, role=none):          if role == qtcore.qt.editrole:             row = qmodelindex.row()             color = qtgui.qcolor(any)             if color.isvalid():                 self._datas[row] = color                 self.datachanged.emit(qmodelindex, qmodelindex, [])                 return true         return false  if __name__ == '__main__':     app = qapplication(sys.argv)     red = qtgui.qcolor(255,0,0)     green = qtgui.qcolor(0, 255, 0)     blue = qtgui.qcolor(0, 0, 255)     colors = [red,green,blue]      model = listmodel(colors)      listview = qtwidgets.qlistview()     listview.setmodel(model)     listview.setwindowtitle('list')     listview.show()      treev = qtwidgets.qtreeview()     treev.setmodel(model)     treev.setwindowtitle('tree')     treev.show()      tablev = qtwidgets.qtableview()     tablev.setmodel(model)     tablev.setwindowtitle('table')     tablev.show()       sys.exit(app.exec_()) 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -