QTableView sections move problem
Unsolved
General and Desktop
-
When I call
tableView->horizontalHeader()->setSectionsMovable(true);
Dragging a section slightly to the right and releasing the mouse button scrolls the table all the way to the left (see gif)
Are there any ways to solve this? Qt Version is 6.5.0. The code is below// main.cpp #include <iostream> #include <QApplication> #include <QTableView> #include <QHeaderView> #include "MyModel.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); auto tableView = new QTableView(); auto model = new MyModel(); tableView->setModel(model); tableView->horizontalHeader()->setSectionsMovable(true); tableView->show(); return app.exec(); }
// MyModel.cpp #include "MyModel.h" MyModel::MyModel(QObject *parent) : QAbstractTableModel(parent) { } int MyModel::rowCount(const QModelIndex &) const { return 20; } int MyModel::columnCount(const QModelIndex &) const { return 20; } QVariant MyModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) return QString("%1, %2") .arg(index.row() + 1) .arg(index.column() + 1); return {}; }
// MyModel.h #ifndef TEST_MYMODEL_H #define TEST_MYMODEL_H #include <QAbstractTableModel> class MyModel : public QAbstractTableModel { Q_OBJECT public: explicit MyModel(QObject *parent = nullptr); int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; }; #endif //TEST_MYMODEL_H