有没有办法用 GTK2 更改标题栏?
我有一个使用 GTK2 用 Ruby 编写的桌面应用程序。这只是一个使用 GTK2 的小型测试应用程序,但我在实现我想要做的事情时遇到了问题。有没有办法使用 GTK2 来访问标题栏(除了设置标题),特别是向其添加一个按钮(在下图中的最小/最大/等旁边,B 旁边)或向菜单添加一个选项单击标题栏上的图标(下图中的 A)时会弹出?
我想可能不会,因为 GTK 旨在与许多不同的窗口管理器一起工作,但我只是想知道是否有。作为一个附带问题,单击“十字”按钮会触发什么事件?目前,如果用户单击窗口消失但程序没有结束 - 我需要捕获该事件并退出程序。
感谢您的帮助,包括敲打我的头并告诉我我是多么愚蠢。
I have a desktop application written in Ruby that is using GTK2. It's just a small test application to play with GTK2, but I'm having problems achieving what I want to do. Is there any way using GTK2 to get at the titlebar (apart from setting the title), specifically to either add a button to it (beside the min/max/etc, B in the below diagram) or to add an option to the menu that pops up when you click the icon on the titlebar (A in the below diagram)?
I'm thinking there might not be because GTK is meant to work with many many different window managers, but I just wondered if there was. As a side question, what event does clicking the 'cross' button fire? At the moment if the user clicks that the window disappears but the program doesn't end - I need to capture that event and quit the program.
Thanks for any help, including hitting me over the head and telling me how silly I am.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,这在 GTK 3.10 及更高版本中可以通过使用 gtk_window_set_titlebar() 实现。它将窗口管理器的标题栏替换为自定义标题栏。
GtkHeaderBar
是一个很好用的自定义标题栏类。但是,您不能使其看起来像窗口管理器那样,因为您不知道用户正在运行哪个窗口管理器。
Note that this is possible in GTK 3.10 and up, by using
gtk_window_set_titlebar()
. It replaces the window manager's title bar with a custom one.GtkHeaderBar
is a good custom title bar class to use.You can't, however, make it look just like the window manager would, because you won't know which window manager the user is running.
不,标题栏归窗口管理器所有,您通常无法直接访问它。
当用户尝试通过单击窗口管理器的按钮关闭窗口时,窗口将收到 删除事件。
No, the title bar is owned by the window manager and you will typically not have direct access to it.
When the user tries to close the window by clicking the window manager's button, the window will receive the delete event.