Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

int QTreeView::sizeHintForColumn ( int  column  )  const [protected, virtual, inherited]

Returns the size hint for the column's width or -1 if there is no model.

If you need to set the width of a given column to a fixed value, call QHeaderView::resizeSection() on the view's header.

If you reimplement this function in a subclass, note that the value you return is only used when resizeColumnToContents() is called. In that case, if a larger column width is required by either the view's header or the item delegate, that width will be used instead.

See also:
QWidget::sizeHint, header()

Reimplemented from QAbstractItemView.

Definition at line 1519 of file qtreeview.cpp.

References QVector< T >::at(), QModelIndex::column(), QVector< T >::count(), QWidget::height, QSize::height(), QAbstractItemView::itemDelegate(), QModelIndex::row(), QModelIndex::sibling(), QWidget::size, QAbstractItemDelegate::sizeHint(), QAbstractSlider::value, QAbstractScrollArea::verticalScrollBar(), QAbstractItemView::viewOptions(), QAbstractScrollArea::viewport(), QSize::width(), and QWidget::y.

Referenced by QTreeView::resizeColumnToContents().

{
    Q_D(const QTreeView);
    if (d->viewItems.count() <= 0)
        return -1;

    QStyleOptionViewItem option = viewOptions();
    QAbstractItemDelegate *delegate = itemDelegate();
    QModelIndex index;

    const QVector<QTreeViewItem> viewItems = d->viewItems;
    int v = verticalScrollBar()->value();
    int h = viewport()->height();
    int i = qMax(d->itemAt(v), 0);
    int c = viewItems.count();
    int s = d->height(i);
    int y = d->topItemDelta(v, s);
    int w = 0;
    QSize size;

    while (y < h && i < c) {
        Q_ASSERT(i != -1);
        index = viewItems.at(i).index;
        if (index.column() != column)
            index = index.sibling(index.row(), column);
        size = delegate->sizeHint(option, index);
        w = qMax(w, size.width() + (column == 0 ? d->indentation(i) : 0));
        y += size.height();
        ++i;
    }

    return w;
}


Generated by  Doxygen 1.6.0   Back to index