[PyQt] Trouble reading a model index from an "untouched" combo box

Demetrius Cassidy dcassidy36 at mass.rr.com
Wed Jan 27 08:38:55 GMT 2010


Just took a peak at QAbstractItemView class and your right it's fully 
implemented. The view is asking the selectionModel what the current 
selected index is, and if it has no selection model (not sure if that's 
even possible) it returns an invalid QModelIndex. QComboBox.currentIndex 
is just asking the QSqlTableModel for the row. It doesn't hurt to make a 
1 line code change to test it out. I use QComboBox.currentIndex in my 
app, though I have no need to change the model in QComboBox.

Andreas Pakulat wrote:
> On 26.01.10 17:41:40, Demetrius Cassidy wrote:
>   
>> I don't think you need to use the view pointer at all - it's
>> returning QAbstractItemView *, which I would assume it would need to
>> be casted to the proper class in C++. If that's so, by design the
>> Abstract class will return an invalid index.
>>     
>
> I don't think so ;) The function currentIndex on the view is not
> virtual, so its implemented in the abstract class already properly.
>
> And to get a model index to index into the model its easier to ask the
> view for it, rather than constructing it yourself with model->index(
> combobox->currentIndex(), <model-column>, QModelIndex())
>
> Andreas
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100127/1164b322/attachment.html>


More information about the PyQt mailing list