GTK Progressbar设置CSS Min宽无效

发布于 2025-01-21 16:53:35 字数 1311 浏览 3 评论 0原文

我尝试在项目中使用较小的水平GTK ::进度栏。

/usr/share/themes/adwaita-maia/gtk-4.0/gtk.css中定义的标准最小宽度为150px:

progressbar.horizontal > trough {
    min-width: 150px;
}

当我将150px更改为150px中时,我可以挤压GTK :: ProgressBar ::小于150px In In 150px In In 150px in应用程序。

所以我试图覆盖这一点。 有类成员

Gtk::ProgressBar **progressBar_channel_buffers;
Glib::RefPtr<Gtk::CssProvider> m_refCssProvider;

在标题文件中,构造函数中

m_refCssProvider = Gtk::CssProvider::create();
m_refCssProvider->load_from_data("progressbar.horizontal  {"
                                 "min-width: 50px;"
                               "}");

progressBar_channel_buffers = new Gtk::ProgressBar*[num_channels];
for (int i = 0; i < num_channels; i++){
    progressBar_channel_buffers[i] = new Gtk::ProgressBar;
    progressBar_channel_buffers[i]->get_style_context()->add_provider(m_refCssProvider, 1000);
}

,我尝试了这没有效果,我想知道为什么。例如,当我更改另一个CSS属性时,我会看到效果。例如,

m_refCssProvider->load_from_data("progressbar.horizontal > trough, progressbar.horizontal > trough > progress  {"
                                 "min-height: 50px;"
                               "}");

显示了预期效果。

你能帮我吗?我在做什么错?我本周开始编程GTK(MM),现在我正处于不知道的时刻。

I try to use a smaller horizontal Gtk::ProgressBar in my project.

The standard minimum width as defined in /usr/share/themes/Adwaita-maia/gtk-4.0/gtk.css is 150px :

progressbar.horizontal > trough {
    min-width: 150px;
}

When I change the 150px to 50px in this file I can squeeze the Gtk::ProgressBar smaller than 150px in the application.

So I tried to override this. In the header file, there are the class members

Gtk::ProgressBar **progressBar_channel_buffers;
Glib::RefPtr<Gtk::CssProvider> m_refCssProvider;

In the constructor, I tried

m_refCssProvider = Gtk::CssProvider::create();
m_refCssProvider->load_from_data("progressbar.horizontal  {"
                                 "min-width: 50px;"
                               "}");

progressBar_channel_buffers = new Gtk::ProgressBar*[num_channels];
for (int i = 0; i < num_channels; i++){
    progressBar_channel_buffers[i] = new Gtk::ProgressBar;
    progressBar_channel_buffers[i]->get_style_context()->add_provider(m_refCssProvider, 1000);
}

This has no effect and I wonder why. When I change for example another CSS property I can see an effect. As an example

m_refCssProvider->load_from_data("progressbar.horizontal > trough, progressbar.horizontal > trough > progress  {"
                                 "min-height: 50px;"
                               "}");

shows the expected effect.

Can you please help me? What am I doing wrong? I started programming Gtk(mm) this week and now I am at a point where I have no idea.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木落 2025-01-28 16:53:35

如果我在上面正确读取您的代码,我认为您唯一错误的事情就是错误地想修改样式属性(高度而不是宽度)。它在您的代码段中指出:

m_refCssProvider->load_from_data("progressbar.horizontal  {"
                             "min-height: 50px;"
                           "}");

虽然我认为您是要输入的:

m_refCssProvider->load_from_data("progressbar.horizontal  {"
                             "min-width: 50px;"
                           "}");

另外,在GTK4的源代码中戳了一下,我确实看到了progressbar窗口小部件实际上是由孩子“槽”“槽”“小窗口和一个孩子”组成的。进度”小部件。这使我推断出显示的进度栏的最终最小宽度将仅限于Progress Bar小部件或其子女小部件的最小宽度最大值。因此,您需要利用“ LOAD_FROM_DATA”语句,其中您不仅将最小宽度值应用于Progress Bar节点,还将最小宽度值应用于槽节点和进度节点。

我希望这是有道理的。

问候。

If I am reading your code correctly above, I think the only thing you did incorrectly was mistype the style attribute you were wanting to modify (height instead of width). In your code snippet, it states:

m_refCssProvider->load_from_data("progressbar.horizontal  {"
                             "min-height: 50px;"
                           "}");

Whereas, I think you meant to type:

m_refCssProvider->load_from_data("progressbar.horizontal  {"
                             "min-width: 50px;"
                           "}");

Also, having poked around in the source code for GTK4, I did see that the progressbar widget is actually comprised of a child "trough" widget and a child "progress" widget. That leads me to deduce that the ultimate minimum width of the progress bar that is displayed would be limited to the largest value for minimum width for either the progress bar widget or its children widgets. Therefore, you would need to utilize the "load_from_data" statement where you not only apply the minimum width value to the progress bar node, but also to the trough node and the progress node.

I hope that makes sense.

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文