ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to add buttons to a customized RViz panel

asked 2019-06-18 05:32:24 -0600

RayROS gravatar image

updated 2019-06-18 09:18:34 -0600

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));
}
edit retag flag offensive close merge delete

Comments

I have not looked into your problem in detail, but this:

view_man->getViewAt(1)->getName() == topView;

is a boolean expression, comparing topView to whatever is returned by view_man->getViewAt(1)->getName().

Did you mean to assign topView to view_man->getViewAt(1)->getName()? Then you'd have to remove a =.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-18 08:40:37 -0600 )edit

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 also QObject::connect: No such slot MyViz::switchToTopView(QString("Side View"))

RayROS gravatar image RayROS  ( 2019-06-18 09:06:12 -0600 )edit

I went through the official documentation about that and I thought that the SIGNAL and SLOT statement should have been correct. Am I missing something?

RayROS gravatar image RayROS  ( 2019-06-18 09:23:46 -0600 )edit

I've not looked at this at all, so I wouldn't be able to help you unfortunately.

gvdhoorn gravatar image gvdhoorn  ( 2019-06-18 10:27:19 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-06-30 10:15:38 -0600

RayROS gravatar image

I figured out the answer to this question and why there was no connection between SIGNAL and SLOT and wanted to share in case someone has my same problem. The small issue was the different notation between C++11 and C++17 and about my question the correct answer is the notation below:

QObject::connect( topViewBtn1, &QPushButton::clicked, [this](){
    switchToTopView(QString("Top View"));
});

As also explained here I hope this could be helpful for others.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-06-18 05:32:24 -0600

Seen: 1,474 times

Last updated: Jun 30 '19