Hi All,<br><br>I tried creating a treeview with checkboxes but I'm unable to select the checkboxes. <br><br>on the flag method I had mentioned it as ItemisuserCheckable but still could not get it working...<br><br>am I missing something here to enable the selection of checkboxes.<br>
<br>A snippet of the code is:<br><br>import sys<br><br>from PyQt4.QtCore import *<br>from PyQt4.QtGui import *<br><br><br><br><br>class StbTreeView(QAbstractListModel):<br>    def __init__(self, args, parent=None):<br>        super(StbTreeView, self).__init__(parent)<br>
        <br>        self.args = args<br>        print self.args<br>        <br>        <br>    def rowCount(self, parent):<br>        return len(self.args)<br>    <br>    def headerData(self, section, orientation, role):<br>
        if role == Qt.DisplayRole:<br>            if orientation == Qt.Horizontal:<br>                return QString("Select STB's")<br><br>    def flags(self, index):<br>        row = index.row()<br>        if row:<br>
            return  Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsSelectable<br><br>    def data(self, index, role=Qt.DisplayRole):<br>        <br>        if role == Qt.DisplayRole:<br>            row = index.row()<br>
            return self.args[row]<br><br>        if role == Qt.CheckStateRole:<br>            <br>            row = index.row()<br>            return QVariant(Qt.Unchecked)<br>       <br><br>    def setData(self, index, value, role):<br>
<br>            <br>        if role == Qt.CheckStateRole:<br>            if value == Qt.Checked:<br>                row = index.row()<br>                selected_stb = self.args[row]<br>                print 'selected_stb is %s' % selected_stb<br>
                print 'Value is %s' % value<br>                self.emit(SIGNAL("dataChanged(QModelIndex,QModelIndex)"),index, index)<br>                return True<br>                #return QVariant(Qt.Checked)<br>
                <br>                <br>    <br><br>def main():<br>    myapp = QApplication(sys.argv)<br>    <br>    data = ['STB1', 'STB2', 'STB3', 'STB4', 'STB5', 'STB6', 'STB7', 'STB8']<br>
    <br>    model = StbTreeView(data)<br>    tree_view = QTreeView()<br>    tree_view.show()<br>    tree_view.setModel(model)<br>    <br>    <br>    myapp.exec_()<br><br><br>if __name__ == '__main__':<br>    main()<br>
<br>