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
#define TREEMODEL_H
#include <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
#ifndef TREEMODEL_H[ATTACH]12947[/ATTACH][ATTACH]12948[/ATTACH][ATTACH]12949[/ATTACH][ATTACH]12950[/ATTACH]
#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
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSqlError>
class sqlTreeModel;
class proxyTreeModel;
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= nullptr
);
private:
sqlTreeModel *plidModel;
proxyTreeModel *proxyPlidModel;
QHash<QString,QPair<int,int> > playlistVideoTracker;
void setupModels();
};
#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_H[ATTACH]12941[/ATTACH][ATTACH]12942[/ATTACH][ATTACH]12943[/ATTACH][ATTACH]12944[/ATTACH][ATTACH]12945[/ATTACH][ATTACH]12946[/ATTACH]
To copy to clipboard, switch view to plain text mode
Bookmarks