[Qt-interest] Using QAbstractTableModel with Custom Class
Mandeep Sandhu
mandeepsandhu.chd at gmail.com
Wed Jun 30 14:45:26 CEST 2010
Oops.
Did not see Andre's reply...so some of it might be a repeat! :)
-mandeep
On Wed, Jun 30, 2010 at 6:14 PM, Mandeep Sandhu
<mandeepsandhu.chd at gmail.com> wrote:
>> All I get in my models view is a single row single column view, no headers
>> or anything.
>
> What are you returning in your rowCount()/columnCount() implementation
> of QAbstractTableModel class?
>
> For rowCount() you should be returning the number of items in your
> QMap. (you should return QMap::size() I think)
> For columnCount(), I think you mentioned 3 columns, so you can simply
> return 3 here.
>
> This should set your table dimensions right at least.
>
> For showing proper headers, re-implement the headerData() fxn. Use
> Qt::Orientation orientation to figure out what to return for
> horizontal/vertical headers.
>
> The "section" var tells you for which column header the view is
> requesting data...eg:
>
> if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
> switch(section) {
> case 0:
> return QVariant(QString("file name"));
> ...
> }
> }
>
> I'm assuming here that your worker thread has relevant API's to
> extract the info when requested by the view. eg: does it have an API
> to get the file name?
>
> I don't think making your worker thread a model subclass is a good
> idea. The actual data part should be kept outside of the model
> implementation. Best to have worker class expose API's which the model
> can query to fetch the actual data.
>
> HTH,
> -mandeep
>
>>
>> Are there any concrete examples demonstrating this out there that anyone
>> knows of? The more and more I look at this the more I'm becoming convinced
>> that it is the Worker class that needs to be derived from
>> QAbstractTableModel. But maybe I'm wrong.
>>
>> --
>> Bill
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>
More information about the Qt-interest-old
mailing list