Re: Scrolling Problems with a Floating Widget



> I haven't tested this, but steps that you probably need to take are:
> 
> 1. create widget hierarchy
> 2. set some sensible minimal size on your GtkTreeView
> 3. interconnect scrollbars with tree view by sharing adjustments
> 
> Minimal size can be set using gtk_widget_set_size_request() and
> adjustment sharing can be achieved using getters for scrollbars and
> gtk_widget_set_scroll_adjustments().

(Just to remind everyone I am using GTK3)

So I have created a small Vala example of this so we can see some code.

I have done what you said, however the issue is that the TreeView,
despite the setting of a size request of (0, 0) is not scrolled, it just
takes up all the space and can't be resized, (screenshot here)
http://i.imgur.com/mzrnc.png

How can I make it so that the TreeView does not do this, so that it can
be scrolled? (Code is at the end)

-- 
Andrew



/*
 * Compile with valac --pkg gtk+-3.0 float.vala
*/

public Gtk.TreeView create_scrollable_widget() {
    // Creates a Treeview with many rows
    Gtk.TreeView treeview = new Gtk.TreeView();
    Gtk.ListStore store = new Gtk.ListStore(1, typeof(string));

    for (int i = 0; i<= 40; i++) {
        Gtk.TreeIter iter;
        store.append(out iter);
        store.set(iter, 0, "Some text to read and scroll", -1);
    }

    Gtk.TreeViewColumn col = new Gtk.TreeViewColumn();
    col.set_title("Text");
    Gtk.CellRendererText cr = new Gtk.CellRendererText();
    col.pack_start(cr, false);
    col.set_attributes(cr, "text", 0);
    treeview.append_column(col);
    treeview.set_model(store);
    return treeview;
}


public int main(string[] args) {
    Gtk.init(ref args);

    // Create widgets
    Gtk.Window window = new Gtk.Window();
    Gtk.Table table = new Gtk.Table(2, 2, false);
    Gtk.VBox vbox = new Gtk.VBox(false, 0);

    Gtk.Adjustment hadjustment = new Gtk.Adjustment(0, 0, 0, 0, 0, 0);
    Gtk.Adjustment vadjustment = new Gtk.Adjustment(0, 0, 0, 0, 0, 0);

    Gtk.HScrollbar hscrollbar = new Gtk.HScrollbar(hadjustment);
    Gtk.VScrollbar vscrollbar = new Gtk.VScrollbar(vadjustment);

    Gtk.TreeView treeview = create_scrollable_widget();

    Gtk.Image floating_widget = new Gtk.Image.from_stock(
        Gtk.Stock.ORIENTATION_LANDSCAPE, Gtk.IconSize.DIALOG);

    // Packing
    table.attach(vbox, 0, 1, 0, 1,
                Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL,
                Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL, 0, 0);
    table.attach(hscrollbar, 0, 1, 1, 2,
                Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL,
                Gtk.AttachOptions.FILL, 0, 0);
    table.attach(vscrollbar, 1, 2, 0, 1,
                Gtk.AttachOptions.FILL,
                Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL, 0, 0);
    vbox.pack_start(floating_widget, false, false);
    vbox.pack_start(treeview, true, true);
    window.add(table);

    // Properties
    treeview.set_hadjustment(hadjustment);
    treeview.set_vadjustment(vadjustment);
    treeview.set_size_request(20, 20);

    window.show_all();
    Gtk.main();
    return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]