How can I prevent the view from scrolling when the user selects an item in a view in Qt 4?
Answer:
In order to only allow scrolling when the user drags the scrollbar, you can reimplement scrollTo() to do nothing. See the documentation:
http://doc.trolltech.com/4.3/qabstractitemview.html#scrollTo
See the following example for a demonstration:
#include <QtGui>
class TableWidget : public QTableWidget
{
public:
TableWidget()
{
setColumnCount(15);
setRowCount(20);
QTimer::singleShot(3000, this, SLOT(testScroll()));
}
void scrollTo ( const QModelIndex & index, ScrollHint hint = EnsureVisible )
{
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
TableWidget table;
table.show();
return app.exec();
}

