开发者

GTK: Make a TreeViewColumn fill the space when treeview is resized

开发者 https://www.devze.com 2022-12-07 21:09 出处:网络
What I want is having default column widths when start, allowing users to adjust the size if they want, and when the treeview is resized (i.e., window resized) make col1 grow/shrink to fill the space.

What I want is having default column widths when start, allowing users to adjust the size if they want, and when the treeview is resized (i.e., window resized) make col1 grow/shrink to fill the space. I thought setting the ExpanderColumn would do it, but when I tried the code below, col2 filled the space. Why is it so?

    private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow"))
    {
        builder.Autoconnect(this);

        DeleteEvent += Window_DeleteEvent;
        
        treestore.AppendValues("God save the King", "UK");
        treestore.AppendValues("The Star-spangled banner", "US");
        
        var col1 = new TreeViewColumn();
        col1.Title = "Col1";
        col1.Sizing = TreeViewColumnSizing.Autosize;
        col1.FixedWidth = 300;
        col1.Resizable = true;
        col1.SortColumnId = 1;
        
        var col2 = new TreeViewColumn();
        col2.Title = "Col2";
        col2.Sizing = TreeViewColumnSizing.Fixed;
        col2.FixedWidth = 100;
        col2.Resizable = true;
        col2.SortColumnId = 2;
        
        var cell1 = new CellRendererText();
        col1.PackStart(cell1, true);
        col1.AddAttribute(cell1, "text", 0);

        var cell2 = new CellRendererText();
        col2.PackStart(cell2, true);
        col2.AddAttribute(cell2, "text", 1);

        tree.AppendColumn(col1);
        tree.AppendColumn(col2);
        tree.Model = treestore;
        tree.ExpanderColumn = col1;
    }

GTK: Make a TreeViewColumn fill the space when treeview is resized

GTK: Make a TreeViewColumn fill the space when treeview is resized

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkWindow" id="MainWindow">
    <property name="can-focus">False</property>
    <property name="title" translatable="yes">Example Window</property>
    <property name="default-width">400</property>
    <property name="default-height">100</property>
    <child>
      <object class="GtkTreeView" id="tree">
        <property name="visible">True</property>
        <property name="can-focus">False开发者_StackOverflow中文版</property>
        <property name="enable-grid-lines">both</property>
        <child internal-child="selection">
          <object class="GtkTreeSelection"/>
        </child>
      </object>
    </child>
  </object>
</interface>
0

精彩评论

暂无评论...
验证码 换一张
取 消