【发布时间】:2020-05-07 16:13:17
【问题描述】:
我正在尝试在 gtkmm-3.0 中设置应用程序范围的 css 样式。这就是我初始化和加载样式的方式:
#include "MainWindow.h"
#include <string>
#include <iostream>
const std::string style = R"(
toolbutton {
border-color : #000000;
border-width : 1px;
border-radius: 0px;
}
)";
void loadStyle()
{
try
{
auto css = Gtk::CssProvider::create();
css->load_from_data(style);
Gtk::StyleContext::add_provider_for_screen(
Gdk::Screen::get_default(), css,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
);
}
catch(const Gtk::CssProviderError error)
{
std::cerr << "Failed to load style:" <<error.code() << std::endl;
}
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv,"com.test");
loadStyle();
MainWindow window(800, 600);
window.show_all();
return app->run(window);
}
MainWindow 只是一个 Gtk::Window,它有一个 Gtk::Toolbar 和几个 Gtk::ToolButton。
但由于某种原因,该样式根本没有应用到我的 ToolButton 上。如果我将样式表选择器更改为“选择所有元素”,它将应用于我的工具按钮:
* {
border-color : #000000;
border-width : 1px;
border-radius: 0px;
}
所以我假设我的代码是正确的,而我的样式表中的选择器是错误的。
但是文档说 GtkToolButton 有一个名为 toolbutton 的 CSS 节点。
我目前没有使用set_name 或add_class 自己设置任何名称或类。
我做错了什么?
【问题讨论】: