<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
hi,<br>
<br>
you always return Qt.Unchecked for Qt.CheckStateRole in the data
method ...<br>
try the attached code.<br>
<br>
bests<br>
Zoltan<br>
<br>
<br>
<br>
<br>
On 2011.03.21. 6:21, vijay swaminathan wrote:
<blockquote
cite="mid:AANLkTi=QrAwO0eCNZm0NE0uUJy2tps8DhF2YqX3Cvdvf@mail.gmail.com"
type="cite">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>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
PyQt mailing list <a class="moz-txt-link-abbreviated" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a class="moz-txt-link-freetext" href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></pre>
</blockquote>
<br>
</body>
</html>