Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView sections move problem

QTableView sections move problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtableviewqtableview c++qtablemodelqheaderview
1 Posts 1 Posters 246 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vadimrm
    wrote on 7 May 2023, 15:56 last edited by vadimrm 5 Jul 2023, 16:15
    #1

    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)

    problem - 01.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
    
    
    1 Reply Last reply
    0

    1/1

    7 May 2023, 15:56

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved