kazaak
19th August 2018, 23:32
Hi,
I've implemented a tree model on top of a QSqlTableModel via a proxy model (QSqlTableModel doesn't work well with parent/child relationships). It works great, except when I hide the first column of the view (id column). I want to hide the id column because I don't want it in the view but once I do, dragging children does not work. Any thoughts? I haven't been able to make any progress on this. code attached and below. Thanks!
sqltreemodel.h
#ifndef TREEMODEL_H12947129481294912950
#define TREEMODEL_H
#include <QSqlTableModel>
class sqlTreeModel : public QSqlTableModel
{
Q_OBJECT
public:
sqlTreeModel(QObject *parent=nullptr);
virtual Qt::DropActions supportedDragActions() const { return Qt::MoveAction; }
virtual Qt::DropActions supportedDropActions() const { return Qt::MoveAction; }
};
#endif // TREEMODEL_H
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSqlError>
class QTreeView;
class sqlTreeModel;
class proxyTreeModel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
private:
QTreeView *treeView;
sqlTreeModel *plidModel;
proxyTreeModel *proxyPlidModel;
QHash<QString,QPair<int,int> > playlistVideoTracker;
QSqlError initdb();
void setupModels();
};
#endif // MAINWINDOW_H129411294212943129441294512946
I've implemented a tree model on top of a QSqlTableModel via a proxy model (QSqlTableModel doesn't work well with parent/child relationships). It works great, except when I hide the first column of the view (id column). I want to hide the id column because I don't want it in the view but once I do, dragging children does not work. Any thoughts? I haven't been able to make any progress on this. code attached and below. Thanks!
sqltreemodel.h
#ifndef TREEMODEL_H12947129481294912950
#define TREEMODEL_H
#include <QSqlTableModel>
class sqlTreeModel : public QSqlTableModel
{
Q_OBJECT
public:
sqlTreeModel(QObject *parent=nullptr);
virtual Qt::DropActions supportedDragActions() const { return Qt::MoveAction; }
virtual Qt::DropActions supportedDropActions() const { return Qt::MoveAction; }
};
#endif // TREEMODEL_H
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSqlError>
class QTreeView;
class sqlTreeModel;
class proxyTreeModel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
private:
QTreeView *treeView;
sqlTreeModel *plidModel;
proxyTreeModel *proxyPlidModel;
QHash<QString,QPair<int,int> > playlistVideoTracker;
QSqlError initdb();
void setupModels();
};
#endif // MAINWINDOW_H129411294212943129441294512946