How to add buttons to a customized RViz panel
Hello, I am sub-classing RViz
to create a small customized panel. I found this and started doing this tutorial. However I was trying to implement a couple of buttons. I did using getNumViews()
function available here.
As I click on the button nothing happens and the view never changes.
Is there something I am missing? Thanks for shedding light on this issues.
Below the code:
myviz.h
public Q_SLOTS:
void switchToTopView(QString viewName);
void switchToSideView(QString viewName);
private:
QString sideView = "Side View";
QString topView = "Top View";
myviz.cpp
MyViz::MyViz(QWidget *parent) : QWidget(parent)
{
// Setting up constructor
QPushButton *topViewBtn = new QPushButton("Top View");
QPushButton *sideViewBtn = new QPushButton("Side View");
QGridLayout* control_layout = new QGridLayout();
control_layout->addWidget(topViewBtn, 3, 0);
control_layout->addWidget(sideViewBtn, 3, 1);
// construct lay-out and render panels next to each other
render_panel = new rviz::RenderPanel();
connect(topViewBtn, SIGNAL(clicked()), this, SLOT(switchToTopView(QString("Top View"))));
connect(sideViewBtn, SIGNAL(clicked()), this, SLOT(switchToSideView(QString("Side View"))));
// Other operations
}
void MyViz::switchToTopView(QString viewName)
{
topView = viewName;
view_man = manager->getViewManager();
view_man->getNumViews();
view_man->getViewAt(1)->getName() = topView;
view_man->setCurrentFrom(view_man->getViewAt(1));
}
void MyViz::switchToSideView(QString viewName)
{
sideView = viewName;
view_man = manager->getViewManager();
view_man->getNumViews();
view_man->getViewAt(2)->getName() = sideView;
view_man->setCurrentFrom(view_man->getViewAt(2));
}
I have not looked into your problem in detail, but this:
is a boolean expression, comparing
topView
to whatever is returned byview_man->getViewAt(1)->getName()
.Did you mean to assign
topView
toview_man->getViewAt(1)->getName()
? Then you'd have to remove a=
.Thanks gvdhoorn for taking the time to read the question. Yes your comment is right and I fixed it to the code but I now get the
QObject::connect: No such slot MyViz::switchToTopView(QString("Top View"))
error from compiler and don't understand why. And alsoQObject::connect: No such slot MyViz::switchToTopView(QString("Side View"))
I went through the official documentation about that and I thought that the
SIGNAL
andSLOT
statement should have been correct. Am I missing something?I've not looked at this at all, so I wouldn't be able to help you unfortunately.