سؤال

I have a QTreeWidget with a bunch of QTreeWidgetItems. Each item has a couple columns. When one of the columns is wider than the width of the widget, there will be a scroll bar at the bottom. When I click on a QTreeWidgetItem inside the column that is wider than the widget, the QTreeWidget will automatically scroll to try and get as much of the column within the widget as possible. I do not want this to happen. How do I turn this off?

هل كانت مفيدة؟

المحلول

This is behaviour is controlled by the QAbstractItemView.autoScroll property, which can be set like this:

treewidget.setAutoScroll(False)

However, this property is mainly used for automatically scrolling the tree widget when dragging items to the edge of the widget's viewport. So if this behaviour is still needed, it might be better to override the tree widget's mouse-press event, instead:

def mousePressEvent(self, event):
    self.setAutoScroll(False)
    QtGui.QTreeWidget.mousePressEvent(self, event)
    self.setAutoScroll(True)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top