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

List:       pykde
Subject:    Re: [PyQt] Model copying
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2013-12-13 13:34:47
Message-ID: CAExHGmSX9wt2jvEBs0u4LB1_Xejz7D5X4_hpqWeb06+MnCdJHg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

On Fri, Dec 13, 2013 at 2:01 PM, Jorge Tornero - Listas <
jtorlistas@gmail.com> wrote:

> Thank you for reading this:
>
> I' ve populated a tablewidget and I want to reuse its (internal) model to
> pouplate a qcombobox . So far, I've done:
>
> 1) I create a qtableview and a model for it as newModel=tableWidget.model()
> 2) I set the model of my combo the same as the qtableview
> 3) I set combobox's view as the qtableview.
>
> Of course it works... but when I remove a item in the "original"
> tablewidget, it gets removed from the combo. I think it's amatter of
> assignmente, etc... but I've tried with copy() and deepcopy() and it throws
> an error:
>
> TypeError: PyQt4.QtCore.QAbstractTableModel represents a C++ abstract
> class and cannot be instantiated
>
> Any idea on how to proceed?
>

Sharing a model only makes sense if you want to make sure that all views
using it show the same data. That also means that all views will drop items
if they are removed from the model, this is intentional and not a bug.

Now if you don't want that, you actually don't want to share the model. So
what you need to do is create a copy of the data that the model uses and
then populate the combobox model with that. Since you use QTableWidget the
underlying data is whatever you used to populate the QTableWidgetItems.
That data is what you need to put into the combobox, you can't just use the
model of the tablewidget.

Andreas

[Attachment #5 (text/html)]

<div dir="ltr">Hi,<div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec \
13, 2013 at 2:01 PM, Jorge Tornero - Listas <span dir="ltr">&lt;<a \
href="mailto:jtorlistas@gmail.com" \
target="_blank">jtorlistas@gmail.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">Thank you for reading this:<br> <br>
I&#39; ve populated a tablewidget and I want to reuse its (internal) model to \
pouplate a qcombobox . So far, I&#39;ve done:<br> <br>
1) I create a qtableview and a model for it as newModel=tableWidget.model()<br>
2) I set the model of my combo the same as the qtableview<br>
3) I set combobox&#39;s view as the qtableview.<br>
<br>
Of course it works... but when I remove a item in the &quot;original&quot; \
tablewidget, it gets removed from the combo. I think it&#39;s amatter of assignmente, \
etc... but I&#39;ve tried with copy() and deepcopy() and it throws an error:<br>

<br>
TypeError: PyQt4.QtCore.<u></u>QAbstractTableModel represents a C++ abstract class \
and cannot be instantiated<br> <br>
Any idea on how to proceed?<br></blockquote><div><br></div><div>Sharing a model only \
makes sense if you want to make sure that all views using it show the same data. That \
also means that all views will drop items if they are removed from the model, this is \
intentional and not a bug.</div> <div><br></div><div>Now if you don&#39;t want that, \
you actually don&#39;t want to share the model. So what you need to do is create a \
copy of the data that the model uses and then populate the combobox model with that. \
Since you use QTableWidget the underlying data is whatever you used to populate the \
QTableWidgetItems. That data is what you need to put into the combobox, you can&#39;t \
just use the model of the tablewidget.</div> <div><br></div><div>Andreas</div><div> \
</div></div></div></div>



_______________________________________________
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