[Qt-interest] item delegates

Scott Aron Bloom Scott.Bloom at onshorecs.com
Wed Mar 9 17:56:57 CET 2011


Unfortunately, I can say, when I have had a similar circumstance, I used
a similar if then else/switch setup..

 

For more complex situations, when I have a data object attached to each
model index, I will actually create a custom role in the model, that
gets the object, and asks the object for delegate editor.

 

Scott

 

From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com
[mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On
Behalf Of Graham Labdon
Sent: Wednesday, March 09, 2011 3:52 AM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] item delegates

 

Hi

I am implementing a Item Delegate for my tree based model.

I need to create a different editor depending upon the item being
edited.

At the moment I am using switch statements to decide which editor to
supply, but as my model grows so do the switch statements.

 

                QWidget* editor;

 

                QModelIndex parentIndex = index.model()->parent(index);

 

                switch (index.model()->parent(index).row())

                {

                                case 0:

                                {

                                                switch (index.row())

                                                {

                                                                case 0:

                                                                case 1:

                                                                {

 
editor = new QLineEdit(parent);

                                                                }

                                                                break;

 

                                                                case 2:

                                                                {

 
QStringList list;

 
Common::Enumerations::surveyUnits().getDisplayStrings(list);

 
editor = new QComboBox(parent);

 
((QComboBox*)editor)->addItems(list);

                                                                }

                                                                break;

                                                }

                                }

                                break;

 

                                case 1:

                                {

                                                editor = new
QLineEdit(parent);

 
((QLineEdit*)editor)->setValidator(new QIntValidator());

                                }

                                break;

                }

                return editor;

 

Is there a better way to achieve this?

 

TIA

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110309/92fe9d1e/attachment.html 


More information about the Qt-interest-old mailing list