Extending the print dialog
| Chapter 21. Printing |

## Extending the print dialog

You may add a custom tab to the print dialog:

- Set the title of the tab via `PrintOperation::set_custom_tab_label()`, create a new widget and return it from the `create_custom_widget` signal handler. You'll probably want this to be a container widget, packed with some others.

- Get the data from the widgets in the `custom_widget_apply` signal handler.

Although the `custom_widget_apply` signal provides the widget you previously created, to simplify things you can keep the widgets you expect to contain some user input as class members. For example, let's say you have a `Gtk::Entry` called `m_Entry` as a member of your `CustomPrintOperation` class:

    Gtk::Widget* CustomPrintOperation::on_create_custom_widget()
    {
      set_custom_tab_label("My custom tab");

      auto hbox = new Gtk::Box(Gtk::Orientation::HORIZONTAL, 8);
      hbox->set_margin(6);

      auto label = Gtk::make_managed<Gtk::Label>("Enter some text: ");
      hbox->append(*label);

      hbox->append(m_Entry);

      return hbox;
    }

    void CustomPrintOperation::on_custom_widget_apply(Gtk::Widget* /* widget */)
    {
      auto user_input = m_Entry.get_text();
      //...
    }

The example in examples/book/printing/advanced demonstrates this.

Export to PDF |  | Preview