That's Cool!...Thanks Paul!



--- On Tue, 4/19/11, Paul Du Bois <[email protected]> wrote:

From: Paul Du Bois <[email protected]>
Subject: RE: [PyQt] Question on QTreeView, interactive expanding/collapsing
To: "James Polk" <[email protected]>, [email protected]
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: [email protected] 
[mailto:[email protected]] On Behalf Of James Polk
Sent: Tuesday, April 19, 2011 2:28 PM
To: [email protected]
Subject: Re: [PyQt] Question on QTreeView, interactive expanding/collapsing  
Whoops,...just found the *-hotkey,....nevermind, lol...



--- On Tue, 4/19/11, James Polk <[email protected]> wrote:
From: James Polk <[email protected]>
Subject: Question on QTreeView, interactive expanding/collapsing
To: [email protected]
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  
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to