ros-visualization/rviz

Set the type of toolbar button used for rviz::Tool plugin

Closed this issue · 9 comments

Is it possible to change the type of button used for a tool plugin?

No. The tool is just represented by a QAction added to a QToolBar, which always creates a QToolButton. The Qt API to add arbitrary widgets is not exposed. What type of button do you think of?

I wanted to add add a drop down menu like the button to remove tools.

I wanted to add add a drop down menu like the button to remove tools.

Actually, the remove-tools thing isn't a drop down combobox, but a menu of actions.
How exactly should the selection in this list (menu or real drop down) effect the behavior of the tool? Are those entries considered "sub-tools" of your tool plugin that you would like to group?

Currently, for each added tool, this slot function simply adds a corresponding action (and tool button):

void VisualizationFrame::addTool(Tool* tool)
{
QAction* action = new QAction(tool->getName(), toolbar_actions_);
action->setIcon(tool->getIcon());
action->setIconText(tool->getName());
action->setCheckable(true);
toolbar_->insertAction(toolbar_separator_, action);
action_to_tool_map_[action] = tool;
tool_to_action_map_[tool] = action;
remove_tool_menu_->addAction(tool->getName());
QObject::connect(tool, &Tool::nameChanged, this, &VisualizationFrame::onToolNameChanged);
}

I wanted to add a tool for changing the rviz theme where you could select (Dark, Light and Default). Right now the tool adds an enum property to the tools property but it would be nice if you could do this form the toolbar with a drop-down menu. On selection it would set the theme.

I see. I don't think that should be done with the tool plugin. A tool primarily defines mouse and keyboard interaction.
However, another suitable plugin class doesn't exist either. You could try dynamic casting context_->getWindowManager() to QMainWindow and then access its toolbar via: findChild<QToolBar*>("Tools").

I will give that a try and report report back.

I assume for this to work it would still need to be associated with one of the available plugin types?

I assume for this to work it would still need to be associated with one of the available plugin types?

Sure.

@rhaschke The propose solution worked. Thank you for the help.