How_to_add_your_own_Qt_Widgets_to_your_action.md 2.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
You might need to add some Qt Widget to your CamiTK action. You can
choose to

  - add parameters as shown [this page](https://camitk.gricad-pages.univ-grenoble-alpes.fr/Docs/Getting%20Started/Examples%20and%20Tutorials/How_to_add_Qt_Widgets_as_additional_action_parameters_for_actions_created_using_the_CamiTK_wizard/)
  - add your own Qt widgets created using the Qt designer as shown [this page](https://camitk.gricad-pages.univ-grenoble-alpes.fr/Docs/Getting%20Started/Examples%20and%20Tutorials/How_to_add_Qt_Widgets_as_additional_action_parameters_for_actions_created_using_the_CamiTK_wizard/#Learning_by_doing)
  - 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:

```c++
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:

```c++
 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:

```c++
myWidget = new ActionWidget(this);
```

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

```c++
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
:

```c++
ActionWidget *actionWidget = dynamic_cast<ActionWidget * >(this->actionWidget);
actionWidget->setButtonVisibility(false);
```