[Qt-interest] QTree* with custom widgets

Bernhard Friedreich friesoft at gmail.com
Tue Mar 17 15:41:35 CET 2009


Andre Somers schrieb:
> Hi,
>
> (By private mail because of issues posting to the list, sorry).
No problem. Actually I'm really glad you're trying to help me :-) Thanks!
>
> What I do if I want to use custom widgets in a view is that I use a 
> small piece of KDE technology that was introduced as Goya. It can 
> nowadays be found under the name "KWidgetItemDelegate". Documentation 
> can be found here: 
> http://api.kde.org/4.2-api/kdelibs-apidocs/kdeui/html/classKWidgetItemDelegate.html 
> while you can download the code from the KDE repository.
>
> You will need the following files:
> kwidgetitemdelegate.cpp
> kwidgetitemdelegate.h
> kwidgetitemdelegate_p.h
> kwidgetitemdelegatepool.cpp
> kwidgetitemdelegatepool_p.h
>
> In your own project, subclass kWidgetItemDelegate. Reimplement 
> createItemWidgets to create the widgets you need for presenting your 
> data. Use updateItemWidgets to  set the data from your model on your 
> widgets and update their layout.
Did that.. altough it didn't work out as expected. I've "ported the 
class to pure Qt", subclassed it and tried to use it.. although the tree 
looks totally f****** up because the widgets sit anywhere/nowhere, text 
appears and disapperas as it likes to.. not comparable to a standard 
table with setIndexWidget/setItemWidget from look and feel (you can also 
feel that when using Goya in the Kwin Settings Dialog.. the buttons 
somehow don't feel like real ones).

Also my requirements are much higher than anything Goya could satisfy .. 
as far as I remember the limitations, back then when Goya was initially 
designed.

In the attachement you can find a picture of how the QWidget in the tree 
should look like (picture was made with a QTreeView and setIndexWidget 
after expanding the tree again (after adding the second row) it was 
perfectly fine.

Would still appreciate any other comments about how to solve this issues :-)
>
> However: note the licence of these files! If their open-source nature 
> is a problem for you, then don't use them.
My project is GPL v2. so that's fine :-)
>
> Regards,
>
> André
>
>
>
> Bernhard Friedreich wrote:
>>
>>> First. Please reply to the mailing list.
>>>
>> Sorry ... totally overlooked that..
>>>
>>>  
>>>
>>> Everything is trade off between the cost of development and 
>>> functionality which includes efficient memory handling and usability.
>>>
>>> You mentioned that it does not matter for you which widget to use.
>>>
>>> As for me this means that the data you need to display is relatively 
>>> small.
>>>
>> 1.) it IS small (sthg. like 4 strings and 2 numbers)
>> 2.) the model just provided the texts for the 0. column atm (but 
>> those texts are always the same so it doesn't really matter)
>>>
>>> So from this point of view, you can safely use QTreeWidget.
>>>
>>>  
>>>
>>> You don’t provide sufficient details what kind of resizing you need,
>>>
>>> but you can probably just resize widgets yourself when it is needed,
>>>
>> Sorry again.. I've made the experience that the longer the text the 
>> fewer people will read it ^^
>>
>> I've got the following requirements:
>>
>> Tree
>>  | - text 1
>>         widget 1 object
>>  | - text 2
>>         widget 2 object
>>  | - text 3
>>         widget 2 object with different "edit triggers" (provided by 
>> the widget itself in a custom way)
>>
>> Widget 1: QLabel with a static text --> so here setIndexWidget or 
>> setItemWidget (depending on the QTree*) would be sufficient.
>> Widget 2: QWidget with a layout and some more widgets inside (some 
>> Labels, Lineedits, Buttons, Comboboxes and maybe some more layouts ^^)
>> The second "widget 2" is just another instance of the same QWidget as 
>> "widget2"
>>
>> When I now press one of the buttons in "Widget 2" some more widgets 
>> should be added to one of the layouts of "Widget 2".
>>
>> Now the case with setIndexWidget/setItemWidget is that the size of 
>> the QTreeWidgetItem (or whatever you'd like to call it) doesn't 
>> change as long as I don't collpase and reopen the tree again.
>>>
>>> This will minimize development cost. I would not start implementing 
>>> anything else untiil it is clear that this appoach will not work for 
>>> me.
>>>
>> Totally understandable -- just didn't thought that it would be sooo 
>> tougth... everything I've done in Qt before was easy-peasy and solved 
>> within hours or at max. 2 days ^^
>>>
>>>  
>>>
>>> Regards,
>>>
>>>    Alex
>>>
>>>  
>>>
>>>  
>>>
>>> ------------------------------------------------------------------------ 
>>>
>>>
>>> *From:* Bernhard Friedreich [mailto:friesoft at gmail.com]
>>> *Sent:* Monday, March 16, 2009 3:17 AM
>>> *To:* Malyushytsky, Alex
>>> *Subject:* Re: [Qt-interest] QTree* with custom widgets
>>>
>>>  
>>>
>>> Because the widgets needs the ability to be resized! (dynamic content)
>>>
>>> From the Qt docu:
>>>
>>> This function should only be used to display static content in the 
>>> place of a tree widget item. If you want to display custom dynamic 
>>> content or implement a custom editor widget, use QTreeView 
>>> <qtreeview.html> and subclassQItemDelegate <qitemdelegate.html> 
>>> instead.
>>>
>>>  
>>>
>>> 2009/3/16 Malyushytsky, Alex <alex at wai.com <mailto:alex at wai.com>>
>>>
>>> Why QTreeWidget::setItemWidget is not working for you?
>>>
>>> void QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int 
>>> column, QWidget * widget )
>>>
>>> Regards,
>>>    Alex
>>>
>>>
>>>
>>>
>>> ________________________________________
>>> From: qt-interest-bounces at trolltech.com 
>>> <mailto:qt-interest-bounces at trolltech.com> 
>>> [mailto:qt-interest-bounces at trolltech.com 
>>> <mailto:qt-interest-bounces at trolltech.com>] On Behalf Of Bernhard 
>>> Friedreich
>>> Sent: Sunday, March 15, 2009 1:44 PM
>>> To: qt-interest at trolltech.com <mailto:qt-interest at trolltech.com>
>>> Subject: [Qt-interest] QTree* with custom widgets
>>>
>>>
>>> Hey!
>>>
>>> I've been fighting with a problem for quite some time now and I've 
>>> now reached the point from which on I have now idea what is left, I 
>>> could try. I really hope you guys (and girls ^^) can help me.
>>>
>>> I want to use a QTreeView or QTreeWidget (doesn't really matter) 
>>> with custom widgets.
>>>
>>> I've got those requirements:
>>> * Custom widgets (different rows = different widgets, 0st column: 
>>> normal description text, 1st column: the widget)
>>> * dynamic resizing (adding widgets at runtime to the custom widget)
>>> * the widgets must be shown all the time (NOT JUST FOR EDITING!)
>>> I've tried setIndexWidget, setItemWidget, a QGraphicsView and 
>>> ItemDelegates with the paint method..
>>>
>>> Already searched on many forums, google and mailings lists but 
>>> nothing useable turned up.
>>>
>>> Here's the thread where I asked for help (provides some more 
>>> information): 
>>> http://www.qtforum.org/article/27021/qtree-with-custom-qwidgets.html
>>>
>>> I'd REALLY appreciate if you could help me... I'm totally lost atm...
>>>
>>> Thanks for your help :-)
>>>
>>> Best regards,
>>> Bernhard Friedreich, Qt fan and developer :-P
>>>
>>> --------------------------------------------------------------------------------------------------- 
>>>
>>> Weidlinger Associates, Inc. made the following annotations.
>>>
>>> "This message and any attachments are solely for the intended 
>>> recipient and may contain confidential or privileged information. If 
>>> you are not the intended recipient, any disclosure, copying, use, or 
>>> distribution of the information included in this message and any 
>>> attachments is prohibited. If you have received this communication 
>>> in error, please notify us by reply e-mail and immediately and 
>>> permanently delete this message and any attachments. Thank you."
>>>
>>> "Please consider our environment before printing this email."
>>>
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>
>>>  
>>>
>>>
>>> “This message and any attachments are solely for the intended 
>>> recipient and may contain confidential or privileged information. If 
>>> you are not the intended recipient, any disclosure, copying, use, or 
>>> distribution of the information included in this message and any 
>>> attachments is prohibited. If you have received this communication 
>>> in error, please notify us by reply e-mail and immediately and 
>>> permanently delete this message and any attachments. Thank you.”
>>> ------------------------------------------------------------------------ 
>>>
>>>
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at trolltech.com
>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>>   
>>
>
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: QTree-Wanted-Behaviour.jpg
Type: image/jpeg
Size: 113226 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090317/8444b44f/attachment.jpg 


More information about the Qt-interest-old mailing list