[Qt-interest] display one database column as two in QTableView

Israel Brewster israel at frontierflying.com
Fri Mar 12 21:28:36 CET 2010


On Mar 12, 2010, at 8:12 AM, Israel Brewster wrote:

> 
> On Mar 9, 2010, at 5:56 AM, Andre Somers wrote:
> 
>> Israel Brewster wrote:
>>> On Mar 8, 2010, at 11:28 AM, André Somers wrote:
>>> 
>>> 
>>>> Alternatively, you could create a proxy model that splits the date column
>>>> into two separate columns. This would also work on databases that don't
>>>> support editable queries.
>>>> 
>>> 
>>> ... I would then need to override the data() and setData() functions to translate between the real model and proxy, and the columnCount function to return one additional column...
>>> 
>> [snip].
> 
> ...However, turns out overriding the row count function only gets me halfway there. It does add another column to the display, and by overriding the data function I can get the first few columns populated the way I want, but the data() function is never called for that last column - it's as though data() is only called for the number of columns in the underlying model. So I guess my next attempt will be to override the columnCount() function of the underlying model as well and see what that does. Hopefully it doesn't just crash the program :-)

Ok, I'm making progress. By overriding the columnCount() function of the QSqlTableModel, I got all the columns I wanted, populated with the data I want. Overriding the setData() function also worked to re-combine the separate date/time columns back to the timestamp. 

However, the last column in my model, while it does display the proper data, is drawn grayed out, as though disabled. Clicking on the column does nothing- I can't select or edit anything in this column. It's as though there is still something, somewhere, thinking that there should be one fewer columns than I am showing, and thus disabling the last column (since the column number is too high). Anyone know how I can fix this? Thanks.

-----------------------------------------------
Israel Brewster
Computer Support Technician II
Era Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100312/6b151867/attachment.bin 
-------------- next part --------------



More information about the Qt-interest-old mailing list