如何将操作按钮添加到 FileChooserDialog?
How do I add action buttons to a FileChooserDialog?
当我尝试显示文件选择器对话框时,它缺少操作按钮:
let dialog = FileChooserDialog::new(Some("Open File"), Some(&window), FileChooserAction::Open);
dialog.run();
我从另一个项目中找到了另一种方法:
let dialog = FileChooserDialog::new_with_buttons::<ApplicationWindow>(
Some("Open File"),
Some(&window),
FileChooserAction::Open,
&[
("_Cancel", ResponseType::Cancel),
("_Open", ResponseType::Accept),
],
);
错误信息是:
no function or associated item named `new_with_buttons` found for type `gtk::FileChooserDialog` in the current scope
我想您需要在创建对话框之后和显示之前使用 add_button
添加按钮:
let dialog = FileChooserDialog::new(Some("Open File"), Some(&window), FileChooserAction::Open);
dialog.add_button("_Cancel", ResponseType::Cancel);
dialog.add_button("_Open", ResponseType::Accept);
dialog.run();
当我尝试显示文件选择器对话框时,它缺少操作按钮:
let dialog = FileChooserDialog::new(Some("Open File"), Some(&window), FileChooserAction::Open);
dialog.run();
我从另一个项目中找到了另一种方法:
let dialog = FileChooserDialog::new_with_buttons::<ApplicationWindow>(
Some("Open File"),
Some(&window),
FileChooserAction::Open,
&[
("_Cancel", ResponseType::Cancel),
("_Open", ResponseType::Accept),
],
);
错误信息是:
no function or associated item named `new_with_buttons` found for type `gtk::FileChooserDialog` in the current scope
我想您需要在创建对话框之后和显示之前使用 add_button
添加按钮:
let dialog = FileChooserDialog::new(Some("Open File"), Some(&window), FileChooserAction::Open);
dialog.add_button("_Cancel", ResponseType::Cancel);
dialog.add_button("_Open", ResponseType::Accept);
dialog.run();