nodeeditor
nodeeditor copied to clipboard
Error with Multiple FlowView Creation
Creating 2 FlowView as following doesn't capture ESC and DELETE key event. if I create only one FlowView, it capture the signals well.
so, I am wonder the logic inside the FlowView.cpp file...because the this instance with the connect call can't know where it should post the event between the 2 instances.
[ excerpt from FlowView.cpp file ]
// setup actions
_clearSelectionAction = new QAction(QStringLiteral("Clear Selection"), this);
_clearSelectionAction->setShortcut(Qt::Key_Escape);
connect(_clearSelectionAction, &QAction::triggered, _scene, &QGraphicsScene::clearSelection);
addAction(_clearSelectionAction);
_deleteSelectionAction = new QAction(QStringLiteral("Delete Selection"), this);
_deleteSelectionAction->setShortcut(Qt::Key_Delete);
connect(_deleteSelectionAction, &QAction::triggered, this, &FlowView::deleteSelectedNodes);
addAction(_deleteSelectionAction);
=============================================
[ Example code to generate multi instances of FlowView which is going to be part of QFrame and it will be docked in MainWindow with tab-style windows ]
class FrameInstA : public QFrame
{
FlowView *mView;
FlowScene *mScene;
};
class FrameInstB : public QFrame
{
FlowView *mView;
FlowScene *mScene;
};
Inside the application logic :
// Dock A Window
mA = new FrameA("A", this);
dockA = new QDockWidget(tr("A"), this);
dockA->setWidget(mA);
addDockWidget(Qt::RightDockWidgetArea, dockA);
// Dock B Window
mB = new FrameB("B", this);
dockB = new QDockWidget(tr("B"), this);
dockB->setWidget(mB);
addDockWidget(Qt::RightDockWidgetArea, dockB);
Due to the multi instances of the FlowView, the eventfilter can't properly work. then, it need a way to assign the key for each QFrame.
[Warning] <> QAction::eventFilter: Ambiguous shortcut overload: Del [Warning] <> QAction::eventFilter: Ambiguous shortcut overload: Esc
setShortcutContext(Qt::WidgetWithChildrenShortcut) solves the problem with limiting the QAction to the focused window.
// setup actions _clearSelectionAction = new QAction(QStringLiteral("Clear Selection"), this); _clearSelectionAction->setShortcut(Qt::Key_Escape);### _clearSelectionAction->setShortcutContext(Qt::WidgetWithChildrenShortcut); connect(_clearSelectionAction, &QAction::triggered, _scene, &QGraphicsScene::clearSelection); addAction(_clearSelectionAction);
_deleteSelectionAction = new QAction(QStringLiteral("Delete Selection"), this); _deleteSelectionAction->setShortcut(Qt::Key_Delete); _deleteSelectionAction->setShortcutContext(Qt::WidgetWithChildrenShortcut); connect(_deleteSelectionAction, &QAction::triggered, this, &FlowView::deleteSelectedNodes); addAction(_deleteSelectionAction);