[Paraview-developers] QToolBar plugin for ParaView

David Thompson david.thompson at kitware.com
Wed Jan 17 14:32:11 EST 2018


Hi all,

I'm working on a ParaView plugin that adds a toolbar. The problem is that the toolbar needs to hold a QWidget (a QComboBox), not a QAction. This doesn't seem supported by ParaView because it does not provide access to its QMainWindow and insists on creating menus/toolbars itself without giving the plugin access to them.

I have a small change to the pqPluginActionGroupBehavior that will provide more flexibility (see below) and will submit a MR if people agree that it's the right way to go about things. The approach it takes is to check the QActionGroup defined in the plugin for a method named "customizeToolBar(QToolBar*)" and call it with the newly-constructed tool bar if the method exists. Any comments?

	Thanks,
	David

PS. This change, plus the addition of an include for <QMetaObject> are all that's needed:

@@ -108,7 +110,17 @@ void pqPluginActionGroupBehavior::addPluginInterface(QObject* iface)
   {
     QToolBar* tb = new QToolBar(splitName[1], mainWindow);
     tb->setObjectName(splitName[1]);
-    tb->addActions(agi->actionGroup()->actions());
+    auto actionGroup = agi->actionGroup();
+    tb->addActions(actionGroup->actions());
+    // If the action group has a public slot named "customizeToolBar" that accepts
+    // a toolbar pointer, invoke that method so that custom widgets may be added.
+    if (actionGroup->metaObject()->indexOfSlot("customizeToolBar(QToolBar*)") >= 0)
+    {
+      QMetaObject::invokeMethod(
+        actionGroup, "customizeToolBar",
+        Qt::DirectConnection,
+        Q_ARG(QToolBar*, tb));
+    }



More information about the Paraview-developers mailing list