Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, February 2008
How to NOT draw lines on QTreeView top-level items?


Message 1 in thread

I have 2 questions about QTreeView:

1. Is there a simple way to make QTreeView not draw lines for top-level
nodes?  I want to keep the expander control (when children are
present) but not the lines.

setRootIsDecorated(false) gets rid of both which is not what I want.

See the pictures attached.  Simple.png is the output of SimpleTreeModel
demo; wanted.png is how I wanted it to look.

2. This is unrelated to (1).  Is it possible to have QTreeView draw the
root node, like the "Desktop" node in explorer on Windows? (see
explorer.png attched.)

-- 
 [ signature omitted ] 

Attachment: simple.PNG
Description: PNG image

Attachment: wanted.PNG
Description: PNG image

Attachment: explorer.PNG
Description: PNG image


Message 2 in thread

On Wed, 06 Feb 2008 14:02:23 +0300, Stephen Lee <sldev438@xxxxxxxxxxxx>  
wrote:

> 2. This is unrelated to (1).  Is it possible to have QTreeView draw the
> root node, like the "Desktop" node in explorer on Windows? (see
> explorer.png attched.)

I guess setFirstColumnSpanned() is what you need.

-- 
 [ signature omitted ] 

Message 3 in thread

On Wednesday 06 February 2008, Stephen Lee wrote:
> I have 2 questions about QTreeView:
>
> 1. Is there a simple way to make QTreeView not draw lines for top-level
> nodes?  I want to keep the expander control (when children are
> present) but not the lines.
>
> setRootIsDecorated(false) gets rid of both which is not what I want.

I have not tried it but I guess that you will have to derive your own tree 
view from QTreeView and reimplement drawBranches() or drawTree() or both. 
When the current index is top-level then return without drawing anything, 
otherwise call the implementation provided by QTreeView.

> See the pictures attached.  Simple.png is the output of SimpleTreeModel
> demo; wanted.png is how I wanted it to look.
>
> 2. This is unrelated to (1).  Is it possible to have QTreeView draw the
> root node, like the "Desktop" node in explorer on Windows? (see
> explorer.png attched.)

That's exactly what you get when you have a visible root node and call 
setRootIsDecorated(false).

Regards,
Bernd

--
 [ signature omitted ] 

Message 4 in thread

Bernd Brandstetter <bbrand@xxxxxxxxxx> wrote:
> 
> I have not tried it but I guess that you will have to derive your own tree 
> view from QTreeView and reimplement drawBranches() or drawTree() or both. 
> When the current index is top-level then return without drawing anything, 
> otherwise call the implementation provided by QTreeView.

Thanks.  I'll look into that.

> That's exactly what you get when you have a visible root node and call 
> setRootIsDecorated(false).

A similar idea came to me after posting the question, which is to have
everything hang off a single child of the root and call
setRootIsDecorated(false)...

But as you suggest, it should be possible to massage the SimpleTreeModel
model to make the root node visible.

Thanks,
Stephen

-- 
 [ signature omitted ]