Testing the table model/view

Eskil Abrahamsen Blomfeldt eblomfel at trolltech.com
Wed Feb 13 10:00:12 CET 2008


Helge Fredriksen wrote:
> Hello!
>
> I just tried to test the model/view programming in Jambi with very 
> simple default implementations of the QAbstractTableModel and 
> QTableView classes. However, the default behavior seem to be a 
> checkbox displayed inside every cell + the text beeing rendered in the 
> upper left corner.
>
> How can I easily remove this behavior?

Hi, Helge.

It is not the default to render checkboxes, your model is most likely 
returning some invalid data for the decoration role of the cell. E.g if 
you make an implementation of data() which returns a string for all 
roles, this could cause the behavior you are seeing plus other arbitrary 
reactions to the invalid data. If you have the data() method return null 
for the decoration role, you will get the default behavior.

As for the alignment of the text, if you wish to e.g. center the text 
completely, you should return a combination of the flags 
Qt.AlignmentFlag.AlignVCenter and Qt.AlignmentFlag.AlignHCenter for the 
role Qt.ItemDataRole.TextAlignmentRole. As a convenience, you can return 
Qt.Alignment.AlignCenter which is a preset combination of center in both 
horizontal and vertical direction.

Now, there's a bug in Qt Jambi 4.3 which means you will have to return 
the bitwise combination of the flags as an *integer* in order for item 
views to properly interpret them. In Qt Jambi 4.4, this will be fixed, 
and you will be able to alternatively return the enum objects themselves 
or an object of the QFlags type Qt.Alignment which represents a 
combination of alignment flags. However, until Qt Jambi 4.4 has been 
released, you will have to call the value() method on the enum or flags 
in order to get its integer value.

Thus:

       return Qt.AlignmentFlag.AlignCenter.value();

or:

    return new Qt.Alignment(Qt.AlignmentFlag.AlignHCenter, 
Qt.AlignmentFlag.AlignVCenter).value();

or:
   
    return Qt.AlignmentFlag.AlignHCenter.value() | 
Qt.AlignmentFlag.AlignVCenter.value();

All of these should work. I've attached an example of how this could be 
done. Hope this helps!


-- Eskil

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TableView.java
Type: text/java
Size: 748 bytes
Desc: not available
Url : http://lists.trolltech.com/pipermail/qt-jambi-interest/attachments/20080213/7dd621c1/attachment.bin 


More information about the Qt-jambi-interest mailing list