如何在快捷方式窗口中显示快捷方式?
Posted
技术标签:
【中文标题】如何在快捷方式窗口中显示快捷方式?【英文标题】:How to show shortcuts in ShortcutsWindow? 【发布时间】:2021-02-09 16:39:11 【问题描述】:我需要一个 ShortcutsWindow
的简单工作示例(使用 Gtkmm 3),其中只有一个不使用 Gtk::Builder
的 ShortcutsShortcut
。
我在网上找不到这样的例子。我可以显示窗口,但不显示快捷方式。
【问题讨论】:
“快捷方式”是什么意思? devdocs.io/gtk~3.24/gtkshortcutswindow 【参考方案1】:这是一个非常简单的例子。您可以从中构建:
#include <gtkmm.h>
#include <iostream>
class MyShortcutsWindow : public Gtk::ShortcutsWindow
public:
MyShortcutsWindow();
private:
Gtk::ShortcutsShortcut m_shortcut;
Gtk::ShortcutsGroup m_group;
Gtk::ShortcutsSection m_section;
;
MyShortcutsWindow::MyShortcutsWindow()
// Prints Gtkmm version:
std::cout << "Gtkmm version : "
<< gtk_get_major_version() << "."
<< gtk_get_minor_version() << "."
<< gtk_get_micro_version()
<< std::endl;
// 1. Create shorcut:
// -------------------------------------------------------------
// Set title:
auto shortcutTitle = m_shortcut.property_title();
shortcutTitle.set_value("Hit that to search");
// Set type:
auto shortcutType = m_shortcut.property_shortcut_type();
shortcutType.set_value(Gtk::SHORTCUT_ACCELERATOR);
// Set accelerator:
auto shortcutAccelerator = m_shortcut.property_accelerator();
shortcutAccelerator.set_value("<Ctrl>f");
// 2. Create shortcut group:
// -------------------------------------------------------------
m_group.add(m_shortcut);
// 3. Create shortcut section:
// -------------------------------------------------------------
m_section.add(m_group);
// Make sure your section is visible. I have found if this is
// not called, your section won't show until you have tried a
// search first (weird):
auto sectionVisibility = m_section.property_visible();
sectionVisibility.set_value(true);
// 4. Add the section to the window:
// -------------------------------------------------------------
add(m_section);
int main(int argc, char *argv[])
auto app = Gtk::Application::create(argc, argv, "so.question.q66123196");
MyShortcutsWindow window;
window.show_all();
return app->run(window);
就我而言,它适用于 Gtkmm 版本 3.22.30。根据文档,您最多需要 3.20 版。
【讨论】:
谢谢。现在工作。我想我搞砸了快捷方式声明。以上是关于如何在快捷方式窗口中显示快捷方式?的主要内容,如果未能解决你的问题,请参考以下文章