[Qt-interest] Alignment in QTableView

Andre Somers andre at familiesomers.nl
Fri May 28 09:49:42 CEST 2010


On 27-5-2010 8:18, Yves Bailly wrote:
> Andre Somers a écrit :
>    
>> On 26-5-2010 17:22, Yves Bailly wrote:
>>      
>>> Here's a (probably) basic question, but I really can't find a
>>> solution. Using a QTableView to display the contents of an
>>> SQL database (using a QSqlTableModel), I would just want to
>>> have a right-aligned column... but I just can't find a non-insane
>>> way of doing this SIMPLE thing...
>>>
>>>        
>> Normally, alignment is controlled by one of the roles for the data
>> method of the model. You have three options:
>> 1) subclass QSqlTableModel and reimplement data to return the correct
>> value for the alignment role and the column you want.
>> 2) create a proxy model implementation that basically does the same
>> (which is a bit more flexible, as you could apply it to other existing
>> models such as the file system model).
>> 3) create a delegate that overrides the alignment set by the model.
>>
>> In my view, all of the above are valid approaches.
>>      
> I've read the thread...
>
> I came asking on the list because I had already found the approaches
> you mention here... I just find all of them insanely complex just to
> change alignment of a column, in a small prototype-like project. They
> may be sensible if it was a 100KLOC project, but it's not.
>
> So I guess I'll just do things "the good'old way", as Rob said, and
> stick with QTableWidget for now.
>
> Thanks all for your inputs.
>
>    
I agree that it should be possible to do this kind of markup without 
having to write classes for it. Having said that, the classes you have 
to write are really simple. Trivial almost. I think it can be done in 10 
- 15 lines of code total. Still too much, I admit, but less than doing 
it through QTableWidget I think.

André




More information about the Qt-interest-old mailing list