[Qt-interest] Alignment in QTableView

Yves Bailly yves.bailly at sescoi.fr
Thu May 27 08:18:22 CEST 2010


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.

-- 
      /- Yves Bailly - Software developper  -\
      \- Sescoi R&D  - http://www.sescoi.fr -/
"The possible is done. The impossible is being done. For miracles,
thanks to allow a little delay."




More information about the Qt-interest-old mailing list