[PyQt] Question on QTreeView, interactive expanding/collapsing

James Polk jpolk5001 at yahoo.com
Wed Apr 20 02:13:59 BST 2011



That's Cool!...Thanks Paul!



--- On Tue, 4/19/11, Paul Du Bois <dubois at doublefine.com> wrote:

From: Paul Du Bois <dubois at doublefine.com>
Subject: RE: [PyQt] Question on QTreeView, interactive expanding/collapsing
To: "James Polk" <jpolk5001 at yahoo.com>, pyqt at riverbankcomputing.com
Date: Tuesday, April 19, 2011, 3:25 PM

If you need hotkey+click then this is the best way I've found to do it      # Implement shift-click to expand/contract      @pyqtSlot(QModelIndex)    def _on_expanded(self, index):        if self._in_shift_press:            self._in_shift_press = False            _recursive_set_expanded(self, index, True)      @pyqtSlot(QModelIndex)    def _on_collapsed(self, index):        if self._in_shift_press:            self._in_shift_press = False            _recursive_set_expanded(self, index, False)      def mousePressEvent(self, evt):        # Make shift-click expand/collapse all        if int(evt.modifiers() & Qt.ShiftModifier) != 0:            self._in_shift_press = True        try:            QTreeView.mousePressEvent(self, evt)        finally:            self._in_shift_press = False  def _recursive_set_expanded(view,
 root, desired):    from collections import deque    root = root.sibling(root.row(), 0)    q = deque([root])    model = view.model()    while q:        idx = q.popleft()        view.setExpanded(idx, desired)        for i in range(model.rowCount(idx)):            q.append(model.index(i,0, idx))  From: pyqt-bounces at riverbankcomputing.com [mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of James Polk
Sent: Tuesday, April 19, 2011 2:28 PM
To: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] Question on QTreeView, interactive expanding/collapsing  
Whoops,...just found the *-hotkey,....nevermind, lol...



--- On Tue, 4/19/11, James Polk <jpolk5001 at yahoo.com> wrote:
From: James Polk <jpolk5001 at yahoo.com>
Subject: Question on QTreeView, interactive expanding/collapsing
To: pyqt at riverbankcomputing.com
Date: Tuesday, April 19, 2011, 2:09 PM
Greetings All,

In a typical QTreeView,...the default behaviour of clicking on a "plus box",
i.e. the branch boxes of the tree, yields a "single box open", or in the case
of collapsing, a "single box closed" event.

Is there any way to use a keyboard modifier, like SHIFT, CTRL, and/or ALT,
to expand or collapse the *whole* tree?

Many other similiar tree structures in other software have this feature.
For example, holding down CTRL and ALT and clicking on any box will
unfold/expand (or collapse) all nodes/branches from that node and all below.
Is there something I'm overlooking? Is this (re-)implementable ?

Many Thanks,
-Jim  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110419/18f7b3f1/attachment.html>


More information about the PyQt mailing list