Gtk 微调器未出现
我试图在计算正在进行时显示 Gtk::Spinner 对象,但似乎没有发生任何事情。代码片段看起来像......
{
Gtk::Spinner spinner;
spinner.start ();
// do some work...
spinner.stop ();
}
我认为旋转器需要知道它出现在哪个对话上,但我看不到任何将其输入到对象中的方法。有谁知道我在哪里可以找到有效的示例?我可以在很多地方找到 Gtk 文档,但这没有多大帮助。
I'm trying to get a Gtk::Spinner object to display while calculations are in progress but nothing appears to be happening. The snippet of code looks like...
{
Gtk::Spinner spinner;
spinner.start ();
// do some work...
spinner.stop ();
}
I'd have thought the spinner needed to know which dialogue it appears over but I can't see any way of feeding that into the object. Does anyone know where I could find a worked example? I can find the Gtk documentation in many places, but that isn't helping much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简而言之,如果屏幕上没有出现 Gtk::Spinner,这里有一个快速检查表:
vbox.pack_start(spinner, Gtk::PACK_SHRINK);
show_all_children();
spinner.start()
以使小部件实际显示并在屏幕上旋转。详细信息:
实际的 Gtk spinner 小部件代码(请参阅函数 gtk_spinner_class_init( ) in gtkspinner.c) 本身不进行任何绘图。事实上它的代码很少。它所做的只是向 gtk 小部件添加 CSS 代码:
因此实际的外观(图标)和动画是由当前主题的 CSS 文件定义的。例如,在 Gtk 的默认主题的 gtk-contained.css 文件中,您会发现以下内容:
这意味着它将自动搜索基本名称为“process-working-symbolic”的适当图像文件”在主题的“图标”目录树中。实际的旋转动画是在同一个 CSS 文件中定义的:
在大多数其他主题中,旋转器小部件的这些 CSS 代码部分几乎是相同的。
现在这里有一个常见问题:在大多数主题中,旋转器图像是一个 SVG 文件(例如通常为“process-working-symbolic.svg”),但库存 Gdk pixbuf 加载程序不支持完全是SVG格式。它们支持各种其他图像文件格式,但要真正允许 Gdk/Gtk 加载 .svg 文件,您需要安装能够执行此操作的第三方 pixbuf 加载程序,例如 librsvg。
替代方案:
如果您不能或不想安装支持 SVG 的 Gdk pixbuf 加载程序(如 librsvg),那么您也可以简单地添加具有相同基本名称的图像文件,但在另一种文件格式,例如“process-working-symbolic.png”到主题的图标目录树中。因此,要么绘制或下载一些旋转图片,然后缩放它,并将它们多次放置到主题的“图标”目录中列出的分辨率,例如:
您还应该知道:每当您执行
spinner.start()
旋转器图标立即出现在屏幕上,但即使在一台不错的机器上,旋转器通常也需要几乎一秒钟的时间才能开始其动画。In short, here is a quick checklist if Gtk::Spinner is not appearing on screen:
vbox.pack_start(spinner, Gtk::PACK_SHRINK);
show_all_children();
spinner.start()
for the widget to actually appear and spin on screen.In detail:
The actual Gtk spinner widget code (see function gtk_spinner_class_init() in gtkspinner.c) is not doing any drawing on its own. In fact its code is very little. All it does is adding CSS code to the gtk widget:
So the actual look (icon) and the animation is defined by your current theme's CSS file. E.g. in Gtk's default theme's gtk-contained.css file you find the following:
Which means it will automatically search for an appropriate image file with base name "process-working-symbolic" in the theme's "icons" directory tree. And the actual spinning animation is defined in the same CSS file by this:
In most other themes these CSS code portions for the spinner widget are pretty much identical.
Now here is a common problem with this: in most themes the spinner image is an SVG file (e.g. typically "process-working-symbolic.svg"), but the stock Gdk pixbuf loaders do not support the SVG format at all. They support a variety of other image file formats, but for actually allowing Gdk/Gtk to load .svg files you need to install a third-party pixbuf loader capable to do so like librsvg.
Alternative:
In case you cannot or don't want to bother to install an SVG capable Gdk pixbuf loader like librsvg, then you can also simply add image file(s) with the same base name, but in another file format like "process-working-symbolic.png" to your theme's icons directory tree. So either draw or download some spinner picture then scale it and place them several times to the resolutions listed in your theme's "icons" directory, e.g.:
Also you should know: Whenever you do
spinner.start()
the spinner icon immediately appears on screen, but even on a decent machine it typically takes almost a second before the spinner starts its animation.您是否调用
并将其添加到某个窗口?
而且,你的计算可能会阻塞UI,因此不会更新。 打电话一次。
偶尔
Did you call
and add it to some window?
Moreover, your calculations may block the UI, so it is not updated. Call
once in a while.
要将鼠标光标更改为“忙”,您可以执行以下操作:
要将其更改回来,请执行
以下操作。
免责声明:我通常使用 C 语言的 GTK 进行工作,并即时翻译了它......
To change the mouse cursor to "busy" you can do the following:
To change it back, do
instead.
Disclaimer: I usually work with GTK in C, and have translated this on the fly...