扩展打印对话框

你可以在打印对话框中添加自定义标签:

  • 通过PrintOperation::set_custom_tab_label()设置标签的标题,创建一个新的部件然后从create_custom_widget的信号处理函数中返回它。你可能希望它是一个容器部件,在其中包含一些其他部件。
  • 从部件的custom_widget_apply的信号处理函数中获取数据。

尽管custom_widget_apply信号提供了你之前创建的部件,但是为了简化操作,你可以保存一些用户输入作为部件类的成员。例如,你可能希望你有一个叫做m_EntryGtk::Entry拥有CustomPrintOperation作为类成员:

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();
  //...
}

examples/book/printing/advanced示例对此进行了演示。