[PyQt] CheckBox TreeView clarification

vijay swaminathan swavijay at gmail.com
Fri Mar 11 05:25:46 GMT 2011


Hi All,

I'm a new bie to Python and I'm developing an application where in I created
a tree view with  checkboxes and associated the view/model to a combo box.

Treeview code:

class StdItemModel(QStandardItemModel):
    def __init__(self, parent = None):
        super(StdItemModel, self).__init__(parent)

class CheckBoxTreeView(QTreeView):
    def __init__(self, parent = None):
        super(CheckBoxTreeView, self).__init__(parent)
        self.mylist =
['STB1','STB2','STB3','STB4','STB5','STB6','STB7','STB8']
        self.MainUI()

    def MainUI(self):
        self.stdmodel = StdItemModel()
        for val in self.mylist:
            item = QStandardItem(val)
            item.setCheckable(True)
            self.stdmodel.appendRow([item])
        self.setModel(self.stdmodel) # Add Elements

This created a tree view of checkboxes. but at the top I see "1" not sure
how do I replace that with STB and I want the tree view to be collapsable.
How do I acheive that ?

when I associate this with the combobox, this tree view is visible inside
the combo box but only one of the checkbox is selectable. where are when I
run the treeview seperately, I can check multiple check boxes. Am I missing
something here?

This is how I associated the tree view to a combo box:

        stb_combobox = QComboBox()
        cbtv = CheckBoxTreeView()
        stb_combobox.setView(cbtv)
        stb_combobox.setModel(cbtv.stdmodel)



-- 
Vijay Swaminathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110311/aa16f138/attachment-0001.html>


More information about the PyQt mailing list