--- qt-everywhere-opensource-src-4.8.5\src\gui\itemviews\qtreeview.cpp	Fri Jun 07 07:16:59 2013
+++ qt-everywhere-opensource-src-4.8.5\src\gui\itemviews\qtreeview.cpp	Thu Jan 30 10:35:30 2014
@@ -1412,6 +1412,12 @@
     QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
     d->hoverBranch = d->itemDecorationAt(hoverPos);
 
+    // walk trough the sections in visual order to find the first visible logical section
+    int visualIndex = 0;
+    while (d->header->isSectionHidden(d->header->logicalIndex(visualIndex)) && visualIndex < d->header->count())
+      visualIndex++;
+    d->firstVisibleLogicalSection = d->header->logicalIndex(visualIndex);
+
     QVector<QRect> rects = region.rects();
     QVector<int> drawn;
     bool multipleRects = (rects.size() > 1);
@@ -1504,11 +1510,11 @@
                                  : logicalIndices->at(currentLogicalSection - 1);
         QStyleOptionViewItemV4::ViewItemPosition pos;
         if (columnCount == 1 || (nextLogicalSection == 0 && prevLogicalSection == -1)
-            || (headerSection == 0 && nextLogicalSection == -1) || spanning)
+            || (headerSection == firstVisibleLogicalSection && nextLogicalSection == -1) || spanning)
             pos = QStyleOptionViewItemV4::OnlyOne;
-        else if (headerSection == 0 || (nextLogicalSection != 0 && prevLogicalSection == -1))
+        else if (headerSection == firstVisibleLogicalSection || (nextLogicalSection != 0 && prevLogicalSection == -1))
             pos = QStyleOptionViewItemV4::Beginning;
-        else if (nextLogicalSection == 0 || nextLogicalSection == -1)
+        else if (nextLogicalSection == firstVisibleLogicalSection || nextLogicalSection == -1)
             pos = QStyleOptionViewItemV4::End;
         else
             pos = QStyleOptionViewItemV4::Middle;
@@ -1563,19 +1569,11 @@
     }
 
     const bool widgetHasFocus = hasFocus();
-    bool currentRowHasFocus = false;
-    if (allColumnsShowFocus && widgetHasFocus && current.isValid()) {
-        // check if the focus index is before or after the visible columns
-        const int r = index.row();
-        for (int c = 0; c < left && !currentRowHasFocus; ++c) {
-            QModelIndex idx = d->model->index(r, c, parent);
-            currentRowHasFocus = (idx == current);
-        }
-        QModelIndex parent = d->model->parent(index);
-        for (int c = right; c < header->count() && !currentRowHasFocus; ++c) {
-            currentRowHasFocus = (d->model->index(r, c, parent) == current);
-        }
-    }
+    bool currentRowHasFocus = allColumnsShowFocus
+                && widgetHasFocus
+                && current.isValid()
+                && current.parent() == index.parent()
+                && current.row() == index.row();
 
     // ### special case: treeviews with multiple columns draw
     // the selections differently than with only one column
@@ -1658,7 +1656,7 @@
            alternate row color was provided by the view. For backward compatibility,
            this is now delegated to the style using PE_PanelViewItemRow which
            does the appropriate fill */
-        if (headerSection == 0) {
+        if (headerSection == d->firstVisibleLogicalSection) {
             const int i = d->indentationForItem(d->current);
             QRect branches(reverse ? position + width - i : position, y, i, height);
             const bool setClipRect = branches.width() > width;
@@ -1885,7 +1883,7 @@
         d->executePostedLayout(); // we need to make sure viewItems is updated
         if (d->itemsExpandable
             && d->expandsOnDoubleClick
-            && d->hasVisibleChildren(persistent)) {
+            && d->hasVisibleChildren(persistent.sibling(persistent.row(), 0))) {
             if (!((i < d->viewItems.count()) && (d->viewItems.at(i).index == firstColumnIndex))) {
                 // find the new index of the item
                 for (i = 0; i < d->viewItems.count(); ++i) {
@@ -3538,7 +3536,7 @@
     executePostedLayout();
     int x = pos.x();
     int column = header->logicalIndexAt(x);
-    if (column != 0)
+    if (column != firstVisibleLogicalSection)
         return -1; // no logical index at x
 
     int viewItemIndex = itemAtCoordinate(pos.y());
@@ -3560,8 +3558,8 @@
         return QRect();
 
     int itemIndentation = indentationForItem(viewItemIndex);
-    int position = header->sectionViewportPosition(0);
-    int size = header->sectionSize(0);
+    int position = header->sectionViewportPosition(firstVisibleLogicalSection);
+    int size = header->sectionSize(firstVisibleLogicalSection);
 
     QRect rect;
     if (q->isRightToLeft())
--- qt-everywhere-opensource-src-4.8.5\src\gui\itemviews\qtreeview_p.h	Fri Jun 07 07:16:59 2013
+++ qt-everywhere-opensource-src-4.8.5\src\gui\itemviews\qtreeview_p.h	Thu Jan 30 10:40:11 2014
@@ -89,7 +89,7 @@
           uniformRowHeights(false), rootDecoration(true),
           itemsExpandable(true), sortingEnabled(false),
           expandsOnDoubleClick(true),
-          allColumnsShowFocus(false), current(0), spanning(false),
+          allColumnsShowFocus(false), current(0), spanning(false), firstVisibleLogicalSection(0),
           animationsEnabled(false), columnResizeTimerID(0),
           autoExpandDelay(-1), hoverBranch(-1), geometryRecursionBlock(false), hasRemovedItems(false) {}
 
@@ -189,6 +189,7 @@
     mutable QPair<int,int> leftAndRight;
     mutable int current;
     mutable bool spanning;
+    mutable int firstVisibleLogicalSection;
 
     // used when expanding and collapsing items
     QSet<QPersistentModelIndex> expandedIndexes;
