QListView with rows containing multiple fields?



  • This might be a routine task for someone, but I've hit a brick wall reading the documentation.

    I'm looking to present something like a QListView but with each row containing more than one editable value.

    For example, say I want to show a person's name, age and phone number in one row, as I might with a table but in the styling and functionality of a list. If I were to click on the name field, that field would become editable, then if I were to click on the age field it would become editable and the name field displayed as normal, an so on.

    Unedited the list may look like this (text version):


    | John Smith 21 025555555 |
    | Mary Smith 32 075555555 |

    etc..

    But whilst editing the name in the first row might look like this ... (my crude impression of a text edit box)


    | John Smi ... 21 025555555 |
    | Mary Smith 32 075555555 |

    Each row would be populated with a consistent arrangement of text boxes, spinboxes and other standard widget representing some sort of basic data model.

    I know a table view with delegates will do this sort of thing, but I specifically need the appearance and functionality of a list view for this task.

    Any suggestions, or even better, examples?

    Thanks in advance.

    Paul Swanson



  • Use either a QTableView or QTreeView and set the properties of the view so as to make it look like a list view. It is not particularly difficult to do. From memory most can be done from within Qt Designer.

    Good luck.



  • I would advice against using a QTreeView if you don't need tree capabilities. It's layout code is more complex than that of QTableView, so it will be more resource intensive. You can make a QTableView look exactly like a QListView with a few lines of code and/or some designer property setting.



  • True but for only a few items the difference is not noticeable. It depends upon the use case the OP has.



  • Of course. But I am used to work with large sets ;-)



  • No need to boast :-D

    Us mere mortals have to make do with smaller portions ;-)



  • You can also try this, This is just a workaround, i tried something like this in VB6.0 sometime back :)

    Make a custom widget and place all the editables widget on it and arrange it, so that it looks like a row you need.

    Now you can use a QScrollArea as parent of the above created widget. Create the widgets dynamically and arrange them in the QScrollArea.

    But you may face problem if the number of rows will exceed a certain limit.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.