[Qt-interest] Alignment of data in a QTableView

Robert Hairgrove evorgriahr at hispeed.ch
Sun Feb 6 16:03:27 CET 2011


On Sun, 2011-02-06 at 06:48 -0800, Jason H wrote:
> Without digging into it, I would guess that the reported Font Metrics are 
> incorrect. (Recorded does not match drawn)
> But I think it is a problem with your 5's because its got the horizontal part 
> but no vertical stem. I think that is as the font is designed.

Perhaps, but this would only concern the clipping, not the alignment.
Misalignment happens with each font I have tried.

Interestingly enough:
It *does* seem to relate to the numerical format. If I replace "0.5000"
with "X_0.5000", it is still top-aligned. However, if I replace the same
value with the string: "dummy", it aligns correctly. The only changes I
made were in the data() function. Here are the relevant bits:

===================================================================
int row = index.row();
int col = index.column();
QString x;
// m_data is a QList<QStringList>...
switch(role) {
case Qt::DisplayRole:
    if (row < m_data.size() && col < m_data.at(row).size()) {
        x = m_data.at(row).at(col);
        if (x.left(3) == "0.5") {
            // this aligns properly:
            retval = QString("dummy");
            // tried this, to same effect:
            // retval = "X_" + x;
        } else {
            retval = x;
        }
    }
    break;
// I also have this:
case Qt::TextAlignmentRole:
    return (Qt::AlignLeft + Qt::AlignVCenter);
    break;
===================================================================

I think it must be a Qt bug. Surely someone must have seen this
before...or not??




More information about the Qt-interest-old mailing list