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.
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.