PDA

View Full Version : To create a TreeView ,like QtDesigner's WidgetBox



babu198649
29th May 2008, 15:10
hi
i need to create a TreeView which should look same as the QtDesigner's WidgetBox(visible at the left side of the designer) . The first level items should be placed inside a rectangular window with the items text on it.

i have gone through the source code of QtDesigner and found that the QItemDelegate class has been subclassed and the subclassed object has been set to QTreeWidget(through setItemDelegate).
i have used the same subclassed delegate file but i am not getting the desired results.
ie. i get two expand symbols. And only after double clicking the items are expanded.

Is there a simple way to make a TreeWidget same as the QtDesigner's WidgetBox TreeWidget.

jpn
29th May 2008, 15:31
i have used the same subclassed delegate file but i am not getting the desired results.
ie. i get two expand symbols.

So you're using SheetDelegate? Apparently something went wrong... but it's hard to say what. The same approach has worked for me.


And only after double clicking the items are expanded.
See WidgetBoxTreeView::handleMousePress().


Is there a simple way to make a TreeWidget same as the QtDesigner's WidgetBox TreeWidget.
You're on the right track. Just follow the Designer implementation. Or use QxtTreeWidget (http://docs.libqxt.org/classQxtTreeWidget.html) :)

babu198649
29th May 2008, 15:54
Thanks for the helpful link.


See WidgetBoxTreeView::handleMousePress().

At first i used the widgetbox.h file to get the idea. Then i found newform.h file(which provides the dialog at the start of QtDesigner)which is much simple .

Any Have ,the link u have given is the best solution:)

One curious question ,How much time it took u to understand the SheetDelegate class and implement it .

jpn
29th May 2008, 22:11
One curious question ,How much time it took u to understand the SheetDelegate class and implement it .
Heh well, the implementation is not that hard find from Qt Designer sources (even if it's something like 140k sloc) once you know what to look for. All you need to find is a QItemDelegate subclass which reimplements paint(). Oh, and I had used QStyle and QStyleOption classes before so the button painting routine was quite obvious... ;)