Re: TreeView column widths



On Wed, 2008-04-23 at 20:50 -0500, Joaquim Schmidlap wrote:

> I have attached a small test program which exhibits the same  
> behavior. I removed the Notebook for clarity, which made no  
> difference. Perhaps this code makes my problem more clear?
> 
> Or, run it and see. Clicking the toggle button hides the first  
> column, and the second column just sort of expands to fill the space  
> that was there. The behavior is similar if there are many columns;  
> it's always the rightmost one which grows.
> 
> Many thanks for any/all insight here.

The attached program adds a HBox and then packs the ScrolledWindow into
that HBox with PACK_SHRINK option.  It's probably not the exact solution
you're looking for (for some reason it becomes right-aligned), but it
might give you an idea of how to accomplish it

-- 
Jonner
#include <gtkmm.h>

class Columns : public Gtk::TreeModel::ColumnRecord
{
public:
    Gtk::TreeModelColumn<int> one;
    Gtk::TreeModelColumn<int> two;

    Columns() { add(one); add(two); }
};

class Window : public Gtk::Window
{
public:
    Window() : Gtk::Window()
        {
            Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(columns);
            for (int i = 1; i < 30; i += 2)
            {
                // populate the model with some data....
                Gtk::ListStore::iterator row = model->append();
                (*row)[columns.one] = i;
                (*row)[columns.two] = i+1;
            }
            view.set_model(model);
            view.append_column("one", columns.one);
            view.append_column("two", columns.two);
    
            add(vbox);
    
            button.set_label("Hide");
            button.signal_toggled().connect(sigc::mem_fun(*this, &Window::onHide));
            scroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
            scroller.add(view);
    
            vbox.pack_start(button, Gtk::PACK_SHRINK);
            vbox.pack_end(hbox);
            hbox.pack_end(scroller, Gtk::PACK_SHRINK);

            // show a few rows
            set_size_request(-1, 200);
            show_all_children();
        }
private:
    void onHide()
        {
            // make the first column visible/invisible
            view.get_column(0)->set_visible(!button.get_active());
        }
    Columns columns;
    Glib::RefPtr<Gtk::ListStore> model;
    Gtk::TreeView view;
    Gtk::VBox vbox;
    Gtk::HBox hbox;
    Gtk::ToggleButton button;
    Gtk::ScrolledWindow scroller;
};

int main(int argc, char ** argv)
{
    Gtk::Main app(argc, argv);
    Window window;
    app.run(window);
}


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