简体   繁体   中英

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#? The api said,

GtkCheckButton:indicator-size has been deprecated since version 3.20 and should not be used in newly-written code. Use CSS min-width and min-height on the indicator node.

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):

    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. 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. But in the GTK4 doc we can find this phrase :

A GtkCheckButton has a main node with name checkbutton. If the “label” property is set, it contains a label child. 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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