[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QTableModel (custom) with QComboBox in a cell... (take 2)
From:       Matt Newell <newellm () blur ! com>
Date:       2008-03-19 16:36:22
Message-ID: 200803190936.23066.newellm () blur ! com
[Download RAW message or body]

On Wednesday 19 March 2008 00:43:46 Dirk Wagener wrote:
> Hi
> I sent this before, but got no replies.
> Here we go again:
>
> I am implementing a custom model for a table view. I have an editable cell
> in which the user can enter a value. What I want to do is to make the cell
> a QComboBox so that the user can enter a text value for the cell OR select
> some value from a drop-down list. I am not using delegates currently.
> What is the correct (easiest) way to achieve this?
>

You either need to write a custom delegate class or a QItemEditorFactory 
class.  I've never used the QItemEditorFactor, i've just used custom 
delegates.

You'll need to implement createEditor, setModelData, and setEditorData.  You 
can pass your data from the model as a qstringlist, or any custom type 
wrapped as a QVariant(You can even use your own roles if needed). For example 
you could pass a QStringList for the editor role and QString for the Display 
role to use as the current value, which would give you enough info to fill in 
a combo box.

Make sure to call setItemDelegate on the view, passing your custom delegate 
class.

Matt
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic