创建一个 Gtk 按钮,背景中有图像,前面有标签
好的,我正在尝试用 C++ (gtkmm 3.0) 创建一个 Gtk 按钮,该按钮在后台有一个图像,我可以根据状态进行更改,在前台有一个标签,我可以根据语言字符串进行更改。我尝试扩展 Gtk::EventBox 类,该类非常适合图像,但我无法在其中添加标签。我尝试扩展 Gtk::Container 类,但无法将其放入我的 Gtk::VButtonBox 中。必须有一种更好的方法来做到这一点,而无需重新发明轮子。
任何建议将不胜感激。
谢谢,保罗
Okay, I'm trying to create a Gtk button in C++ (gtkmm 3.0) that has an image in the background that I can change depending on state, and a label in the foreground that I can change depending on a language string. I tried extending the Gtk::EventBox class which works great for the image, but I can't put a label in it. I tried extending Gtk::Container class but then I can't put it in my Gtk::VButtonBox. There has to be a better way of doing this without re-inventing the wheel.
Any suggestions would be greatly appreciated.
Thanks, Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可行:
我用background:#F00测试了它,它将按钮转换为漂亮的红色,所以它也应该适用于图像,只需遵守CSS标准。您基本上可以做所有事情,例如更改字体、更改按钮标签的填充等等:-)
This should work:
I tested it with background:#F00 which transformed the button to a nice red, so it should also work with images, just keep to css standards. You can do basically everything, like change the font with, change padding of your button label and so on :-)
实际上你需要发明轮子。您需要的是两个小部件的组合。我知道 Gedit、Nautilus 中有类似的实现,而新的 Gtk+ 3.1.X 包含一个名为 GtkOverlay 的小部件。
它来自此处。你有两个选择,你等待它出来,或者你复制代码并使其适应你的应用程序,直到新的 Gtk+ 发布。
Actually you will need to invent the wheel. What you need is composition of two widgets. I know there's a implementation of someting like that in Gedit, Nautilus, and the new Gtk+ 3.1.X includes a widget that does something like that called GtkOverlay.
That comes from here. You have two choices, you wait for it to come out, or you copy and the code and adapt it to your app till the new Gtk+ get released.