【问题标题】:how to set size for the indicator of a Gtk# checkbutton widget?如何为 Gtk# checkbutton 小部件的指示器设置大小?
【发布时间】:2020-04-29 13:41:51
【问题描述】:

谁能告诉我如何更改 gtk# 中检查按钮的白色方块(指示器?)的大小? api说,

GtkCheckButton:indicator-size 自 3.20 版以来已被弃用,不应在新编写的代码中使用。在指标节点上使用 CSS min-width 和 min-height。

但是这个“在指标节点上”指的是什么?现在如何更改指标的大小?顺便说一句,我正在 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();
    }

下面的style.css 是我一直在尝试的语法,但它们都不起作用。我把它们都放在了这里。

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;    
}

请帮忙!

【问题讨论】:

    标签: c# css checkbox monodevelop gtk#


    【解决方案1】:

    老问题,但也许可以帮助其他人。

    你的一条线很好,试着去掉其他的。

    要修改检查按钮的指示节点,您可以添加

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

    事实上,indicator 节点是一个检查按钮的check(如果检查按钮被分组或者它是一个单选按钮,则为radio)。 gtk3 文档中并不清楚。但是在 GTK4 文档中我们可以找到这句话:

    GtkCheckButton 有一个名为 checkbutton 的主节点。如果设置了“label”属性,则它包含一个子标签。指示节点在未设置组时命名为check,如果checkbutton与其他checkbutton一起分组,则为radio。

    您还可以过滤按钮的状态:

    checkbutton:checked check{
    background: #F00000;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多