QUndoStack across 2 cpps? QTreeView and QGraphicsScene
-
@SGaist Yeah i probably mean the editor cause my delegate is visible trough its paint event even if the editor is closed, right?
Now i click on one position of my delegate (the editor is still closed/or should stay closed) but i still want to change the Qt::CheckStateRole of that indexes delegate.
Is this understandable? Thanks for your help and time too. Can't say that often enough.
Also could i just add a setter function in my graphicsscene and set the model from the treeview? As said i have access from the treeview to the model object and the graphicsscene. Like this:
#include "ViewLayerList.h" #include <QHBoxLayout> #include <QCheckBox> #include <QLabel> #include "ViewLayerDropIndicatorStyle.h" #include <QMouseEvent> #include "resizablepixmapitem.h" #include <QHeaderView> #include <QPushButton> #include <QTimer> #include <QApplication> #include <QDrag> #include <QCursor> #include <QMimeData> #include <QApplication> #include <QFile> #include <QDataStream> #include <QJsonDocument> #include <QJsonObject> #include <QJsonArray> #include <QUndoCommand> #include "CommandManager.h" ViewLayerList::ViewLayerList(CustomGraphicsScene *scene, QWidget *parent) : QTreeView{parent}, scene_durchgereicht(scene) { setStyle(new ViewLayerDropIndicatorStyle(style())); // Ändern Sie den Abstand zwischen den Items und der vertikalen Scrollbar setViewportMargins(0, 0, 50, 0); // Passen Sie den rechten Rand (20) an Ihre Anforderungen an //Versteckt die sinnlose Kopfzeile setHeaderHidden(true); setRootIsDecorated(true); setMouseTracking(true); mydelegate = new ViewLayerItemDelegate(this); model = new ViewLayerStandartItemModel(0,1,this); scene_durchgereicht->setModel(model); //Dieses exakte model }
-
bumping this
-
@StudentScripter your tree view has no reason to be doing that setup with the scene. They share a model, they don't need to know about each other.
As for the delegate, your goal is clear, and again, the editorEvent is what you want to use to implement the behavior you want.
-
@SGaist Well but as i understand it with
model = new ViewLayerStandartItemModel(0,1,this);
im creating a new instance of this class, a new object. So in order to have access to the same model i have to pass the object i create in the treeview trough to the scene.
Is this a mistake? How should i do it instead? -
@StudentScripter you should create the model in the class that manages the ViewLayerList object and set it on both objects there. In the absolute, with the code you show, ViewLayerList is not even needed unless there are some additional function you are implementing. If not, then just use QTreeView directly and configure it in the class managing it.
-
@SGaist Yes im implementing additional functions in the qtreeview/ViewLayerList, thats why i subclassed it. Im creating the model object directly in ViewLayerLists constructor, cause i use that model mostly in this cpp.
So i guess my approach with giving the model from there to the scene is okish?
-
@StudentScripter no, it makes that class know another one just for the purpose of sharing the model. That's tight coupling for the bad reasons.
-
@JonB said in QUndoStack across 2 cpps? QTreeView and QGraphicsScene:
The model code can be kept in its own/class/module/file, that is included into both the tree view & graphics scene classes, they should not need to see each other directly. This would be my inclination.
-
@StudentScripter Yes, a suitable public getter & setter for the model called from each of the
QTreeView
andQGraphicsScene
modules. -
@StudentScripter QTreeView already has a setter for the model. You just need to add one to your QGraphicsScene subclass.
-
@StudentScripter great !
Then please mark the model as solved using the "Topic Tools" button or the dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)
-