[PyQt] Question regarding single model and multiple views...
bvz
bvz at c381.com
Thu Oct 1 02:51:39 BST 2009
Thanks for the quick reply.
I was considering that (hiding columns) but that seems really really
inefficient. There could be as many as 25 tables with 7-8 columns each (but
not much data... rarely more than 20 rows). Hiding columns would mean a lot
of duplicated info...
<scratches head>
...unless QT is smart enough not to populate the hidden columns? That
actually sounds like it could be the case here. Hmmm.
Your other suggestion to write a wrapper has me a little confused. My data
model already has the smarts to do all the filtering, it just doesn't know
what table is requesting it. I don't understand how wrapping it in anything
gets me any additional info.
I was considering subClassing QTableView and overriding the setData and data
methods. But of course that is just a lot of big talk from a small guy...
I don't know what the implications of doing something like that are.
Matt Newell wrote:
>
> On Wednesday 30 September 2009 17:08:40 bvz wrote:
>> Hello,
>>
>> I am new(ish) to PyQt and I am trying to build a simple app.
>>
>> The app has several tables that I want to point to a single model (which
>> will load and store all the data).
>>
>> Each table is responsible for displaying a different set of columns from
>> the model. I.e. table 1 will show columns 1-4, table 2 columns 5-11,
>> etc... The app does not know how many tables there will be ahead of time,
>> nor does it know how many columns will be displayed in each table. Both
>> of
>> these are set by reading a config file.
>>
>> I have a version working where I use a QTableWidget and manually sync the
>> data from the "model" (not actually a subclass of QAbstractTableModel).
>> But there are some issues with this and, anyway, it isn't the "correct"
>> way
>> of working as far as I can tell.
>>
>> I really want to update the app to use the QAbstractTableModel (no
>> delegates). I mostly understand the process and am pretty far along with
>> one exception. How do I translate the "actual" column index in the table
>> to the associated index in the model. I.e. if the user updates a cell in
>> column 3 of the 2nd table, that might actually be a bit of data that is
>> in
>> column 7 of the model. I need to be able to map the table column to the
>> model column and vice versa.
>>
>> So I am wondering, is there some way the table view can send along an
>> offset every time it tries to send data to or from the model? If I can
>> get
>> that info, I can always translate inside the model and return/set the
>> correct data.
>>
>> Thanks.
> The indexes should always match up. Just use QTableView::setColumnHidden
> to
> hide the columns that aren't needed for each view.
>
> If for some reason that didn't work it would be somewhat trivial to write
> a
> wrapper model that simply provides a subset of the real model. Something
> like QSortFilterProxyModel, only a much simpler implementation as the
> mapping
> is always a constant operation.
>
> Matt
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
--
View this message in context: http://www.nabble.com/Question-regarding-single-model-and-multiple-views...-tp25691301p25692011.html
Sent from the PyQt mailing list archive at Nabble.com.
More information about the PyQt
mailing list