简体   繁体   English

如何为 Gtk# checkbutton 小部件的指示器设置大小?

[英]how to set size for the indicator of a Gtk# checkbutton widget?

Can someone please tell me how to change the size of the white square(the indicator?) of a checkbutton in gtk#?有人可以告诉我如何更改 gtk# 中复选按钮的白色方块(指示器?)的大小吗? The api said, api说,

GtkCheckButton:indicator-size has been deprecated since version 3.20 and should not be used in newly-written code. GtkCheckButton:indicator-size 自 3.20 版起已弃用,不应在新编写的代码中使用。 Use CSS min-width and min-height on the indicator node.在指标节点上使用 CSS min-width 和 min-height。

But what is this "on the indicator node" referring to?但是这个“在指标节点上”指的是什么? How to change the size of the indicator now?现在如何更改指标的大小? BTW, I am writing C# on linux (monodevelop):顺便说一句,我正在 linux (monodevelop) 上编写 C#:

    static void Main()
    {
        Gtk.CssProvider cssProvider= new CssProvider();
        cssProvider.LoadFromPath("style.css"); //connect to a css file defining the checkbutton's style property

        Application.Init();
        Gtk.Window win = new Gtk.Window("hello");
        win.SetDefaultSize(600,240);
        win.StyleContext.AddProvider(cssProvider,1);



        Gtk.HeaderBar win_title_bar = new HeaderBar();
        Gtk.Label title_bar_title = new Label();
        title_bar_title.Markup = "<span font-size=\"14000\"><b>PLZ Help!</b></span>";
        title_bar_title.MarginStart = 10;
        win_title_bar.PackStart(title_bar_title);
        win_title_bar.ShowCloseButton = true;
        win.Titlebar = win_title_bar;


        Gtk.VBox main_vbox = new VBox();
        win.Add(main_vbox);

        Gtk.Label lbl1 = new Label();
        lbl1.Name = "lbl1";
        lbl1.Markup = "<span font-size=\"12000\">lbl of the checkbutton</span>";
        lbl1.MarginStart = 10;
        Gtk.CheckButton chk1 = new CheckButton();
        chk1.Name = "chk1";
        chk1.Add(lbl1);

        chk1.StyleContext.AddProvider(cssProvider, 1);//telling chk1 to read the style code in style.css

        Gtk.Alignment chk_align = new Alignment(0.5f,0f,0,0);
        chk_align.Add(chk1);
        main_vbox.PackStart(chk_align, false, false, 0);

        win.DeleteEvent += delete_event;
        win.ShowAll();
        Application.Run();
    }


    static void delete_event(object obj, DeleteEventArgs args)
    {
        Console.WriteLine("Quit");
        Application.Quit();
    }

The following style.css is the syntax I have been trying out, but none of them worked.下面的style.css是我一直在尝试的语法,但都没有奏效。 I put them all together in here.我把它们都放在了这里。

checkbutton indicator {
    min-width:30px;
    min-height:30px;    
}

checkbutton:indicator {
    min-width:30px;
    min-height:30px;    
}

.indicator {
    min-width:30px;
    min-height:30px;    
}

checkbutton check {
    min-width:30px;
    min-height:30px;    
}

check {
    min-width:30px;
    min-height:30px;    
}

indicator {
    min-width:30px;
    min-height:30px;    
}

Please Help!请帮忙!

Old question but maybe that can help someone else.老问题,但也许这可以帮助其他人。

One of your line is good, try removing the others.你的一条线很好,试着去掉其他的。

To modify the indicator node of a checkbutton you can add要修改检查按钮的指示器节点,您可以添加

checkbutton check{
min-width: 30px;
max-height: 30px;
}

In fact, the indicator node is check for a checkbutton (or radio if the checkbutton is grouped or if it's a radiobutton).事实上,指标节点正在检查一个复选按钮(如果复选按钮被分组或者它是一个单选按钮,则检查单选按钮)。 It wasn't clear in the gtk3 documentation.在 gtk3 文档中并不清楚。 But in the GTK4 doc we can find this phrase :但是在 GTK4 文档中,我们可以找到这句话:

A GtkCheckButton has a main node with name checkbutton. GtkCheckButton 有一个名为 checkbutton 的主节点。 If the “label” property is set, it contains a label child.如果设置了“label”属性,则它包含一个标签子项。 The indicator node is named check when no group is set, and radio if the checkbutton is grouped together with other checkbuttons.当没有设置组时,指示器节点被命名为检查,如果检查按钮与其他检查按钮组合在一起,则为单选。

you can also filter the state of the button :您还可以过滤按钮的状态:

checkbutton:checked check{
background: #F00000;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM