Item Delegates in a QAbtstractItemModel ...

88 views
Skip to first unread message

Geoff Harvey

unread,
Feb 17, 2014, 3:23:28 PM2/17/14
to python_in...@googlegroups.com
This is actually kind of a follow-up to olheiros' question about item delegates.

I'm using a QTreeView to display a QAbstractItemModel with (for now) two columns, the first of which is editable.

I'd like to *always* display the first column as a QLineEdit, but I can't figure out how to use a QStyledItemDelegate to do so.

Any pointers? I haven't been able to abstract the correct methods from the stuff I've found online; could be my google-fu is not very strong.

Thanks a bunch,

hoaf

Justin Israel

unread,
Feb 18, 2014, 1:01:09 AM2/18/14
to python_in...@googlegroups.com
Maybe olheiros could share his code for a full example.
Did you implement the methods described in the previous thread, and then call openPersistentEditor() on the cells in your column?


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAH5d3sDrj8XL%3Dm_ccMCdZU4m%3Dpk-YCcUaCF_dny8B%3Dxf4-J6TQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ricardo Viana

unread,
Feb 18, 2014, 3:06:15 AM2/18/14
to python_in...@googlegroups.com
I may be wrong but i think if you default your cell to a QlineEdit it always appear blank waiting for input. At least thats what happens to me if i use openPersistentEditor() along with QLineEdit on my previous example. I will post the link to my example as soon as get to work.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAH5d3sDrj8XL%3Dm_ccMCdZU4m%3Dpk-YCcUaCF_dny8B%3Dxf4-J6TQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


--
Sent from Mobile

Ricardo Viana

unread,
Feb 18, 2014, 6:08:04 AM2/18/14
to python_in...@googlegroups.com
Here is the link:

https://gist.github.com/RicardoViana/8961047

in the end what makes the editor widgets stay up is this part:

but like i said if you want the QLineEdit to stay up, it will give you a blank, waiting for input.
at least that's what i get.

best
Ricardo

------------------------------------------------------------

for row in range(0, len(headers)):
self.listWidget.openPersistentEditor(self.model.index(row, 2))
self.listWidget.openPersistentEditor(self.model.index(row, 3))

------------------------------------------------------------

Geoff Harvey

unread,
Feb 18, 2014, 1:36:11 PM2/18/14
to python_in...@googlegroups.com
That looks great!

... but I'm worried that it would bog down in situations where my model(view) has a large amount of items.

I was thinking that I could paint the resemblance of a QLineEdit in the appropriate locations and open an editor on single- or double-click using delegates and some QStyle magic.

I think the fact that I can't find anything on the interwebs that can help me with this must mean it's either a) not that popular, b) difficult, or c) all of the above.

My reasoning behind trying this is so that the users of my software (in Maya) won't have to click a lot to figure out which cells/entries are editable as they'll be clearly marked as QLineEdits instead of flat, double-clickable fields.

Make sense?

Thanks for the help,

hoaf



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Justin Israel

unread,
Feb 18, 2014, 1:59:53 PM2/18/14
to python_in...@googlegroups.com

You might want to test that theory. I would think a QLineEdit painting itself in C++ as a persistent editor might be faster than you painting the look of a QLineEdit in python.
If your goal is to indicate which cells are editable, I am sure you could use some other decoration approach like slightly different background shades. Then a user could see the editable cells and double click them to start the editor widget.

Geoff Harvey

unread,
Feb 18, 2014, 2:06:36 PM2/18/14
to python_in...@googlegroups.com
That's a fair point -- I'm basing my fears on what I've noticed in similar situations with more complicated widgets (ie, QComboBoxes).

Then again, I'm all for learning new stuff on the company dime. :)

hoaf
Reply all
Reply to author
Forward
0 new messages