- const int count = qMin(rowCount, maxRowCount);
- const QStyleOptionViewItem option = viewOptions();
- for (int row = 0; row < count; ++row) {
- const QModelIndex index = dirModel->index(row, column);
- const int width = itemDelegate()->sizeHint(option, index).width();
- if (width > columnWidth[column]) {
- columnWidth[column] = width;
+ if (rowCount > 0) {
+ const QAbstractProxyModel* proxyModel = qobject_cast<const QAbstractProxyModel*>(model());
+ const KDirModel* dirModel = qobject_cast<const KDirModel*>(proxyModel->sourceModel());
+
+ const int count = qMin(rowCount, maxRowCount);
+ const QStyleOptionViewItem option = viewOptions();
+ for (int row = 0; row < count; ++row) {
+ const QModelIndex index = dirModel->index(row, column);
+ const int width = itemDelegate()->sizeHint(option, index).width();
+ if (width > columnWidth[column]) {
+ columnWidth[column] = width;
+ }