PDA

View Full Version : Autoscroll TableView when Dragging Column



stefanadelbert
21st June 2011, 02:11
I would like to be able to have a QTableView or QTreeView autoscroll when a column is dragged to either the far left or far right of the viewport.

This is how I'm currently creating and setting up a QTreeView (in a custom widget):


treeView = new QTreeView(this);
// model = ...
treeView->setModel(model);
treeView->setFocusPolicy(Qt::NoFocus);
treeView->setEditTriggers(QAbstractItemView::NoEditTriggers) ;
treeView->setAlternatingRowColors(true);
treeView->setAllColumnsShowFocus(true);
treeView->setSelectionMode(QAbstractItemView::ExtendedSelect ion);
treeView->setSelectionBehavior(QAbstractItemView::SelectRows );
treeView->setVerticalScrollMode(QAbstractItemView::ScrollPer Pixel);
treeView->setHorizontalScrollMode(QAbstractItemView::ScrollP erPixel);
treeView->setSortingEnabled(false);
treeView->setUniformRowHeights(true);

treeView->header()->setDefaultAlignment(Qt::AlignCenter);
treeView->header()->setDefaultAlignment(Qt::AlignHCenter);
treeView->header()->setHighlightSections(false);
treeView->header()->setMovable(true);
treeView->header()->setStretchLastSection(true);

I've tried setting AutoScroll, which made no difference (expected since AutoScroll==true by default).

Is this actually an available feature of the QAbstractItemView or do I need to implement this behaviour myself?

Added after 21 minutes:

Based on Qt 4.7.2 documentation:


autoScroll : bool
This property holds whether autoscrolling in drag move events is enabled.
If this property is set to true (the default), the QAbstractItemView automatically scrolls the contents of the view if the user drags within 16 pixels of the viewport edge. If the current item changes, then the view will scroll automatically to ensure that the current item is fully visible.
This property only works if the viewport accepts drops. Autoscroll is switched off by setting this property to false.

I tried calling setAcceptDrops(true) on both the QTreeView/QTableView and on their QHeaderView, but this made no difference.

stefanadelbert
23rd June 2011, 04:39
Surely someone must have wanted this to work at some point. The viewport of a QTableView and QTreeView supports autoscroll for drag and drop, so surely there is support for dragging of column headers too. Anyone?

cgtime
1st September 2012, 01:35
I'm having the same problem, although this is nearly a year later... anybody see this same thing? Anybody? I'm also using 4.7.2. It would be nice to autoscroll on dragging.

TheGrimace
13th November 2012, 17:43
post removed