Skip to content

How to add your own Qt Widgets to your action

You might need to add some Qt Widget to your CamiTK action. You can choose to

  • add parameters as shown this page
  • add your own Qt widgets created using the Qt designer as shown this page
  • mix the default CamiTK action widget with your own widget. That’s what you will learn with this topic.

How is built the default action widget ?

The default action widget is a QWidget . This widget contains a QLayout. This layout contains three objects:

  • The first object (indice 0) is the name of the action.
  • The second object (indice 1) contains the panel containing the action’s properties (“Description”, “target” and “parameters”).
  • The third object (indice 2) is the panel containing the two buttons “Apply” and “Revert”.

You can insert your own widget in this layout at one of the previous indice.

Create your widget

You can create your widget using the Qt Designer or simply by using Qt objects. For example, create a new QPushButton:

1
2
QPushButton *yourButton = new QPushButton("The text of your button");
QObject::connect(saveButton, SIGNAL(released()), this, SLOT(your_callback()));

Add your widget in the default action widget

And then add your widget in the default widget, ie add your widget in the default action widget layout:

1
2
3
 QLayout *informationFrameLayout = Action::getWidget()->layout();
 informationFrameLayout->addWidget(yourButton); // add the widget at the end of the layout
 Action::getWidget()->setLayout(informationFrameLayout);

You can also declare the action widget as a member of your action class, and instanciate it as the default action widget:

1
myWidget = new ActionWidget(this);

And then you get the layout of the widget to insert your own widget in it:

1
2
QBoxLayout * informationFrameLayout = dynamic_cast<QBoxLayout*>(myWidget->layout());
informationFrameLayout->insertWidget(0, yourButton); // insert the widget at the given index

You might also need to hide the default buttons :

1
2
ActionWidget *actionWidget = dynamic_cast<ActionWidget * >(this->actionWidget);
actionWidget->setButtonVisibility(false);