Column grow preventing

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Column grow preventing

Glus Xof
Hello guys,

Crazy to find out how to force the message lines of inside the "Problem Attached Code" wrapping when data in a treeview model becomes longer than the original/previous column size.
Can prevent the column grows each time of model updates ???

Any help/idea ??

*** Problem Attached Code ***

#include <gtkmm.h>
#include <iostream>
#include <vector>

class MyWindow
:
    public Gtk::Window
{
public:

    MyWindow();
    virtual ~MyWindow();
   
private:

    void fill_data();
   
    void on_button_next_clicked();
   
    std::vector<Glib::ustring> messages;
    gint current_idx;
   
    // * * * *

    Gtk::Grid grid;
   
    Gtk::ScrolledWindow scrolled;
    Gtk::TreeView treeview;
   
    Gtk::ButtonBox buttonbox;
    Gtk::Button bt_close;
    Gtk::Button bt_next;
   
    class ModelColumns
    :
        public Gtk::TreeModel::ColumnRecord
    {
    public:
   
        ModelColumns()
        {
            add (id);
            add (message);
        }
       
        Gtk::TreeModelColumn<gint> id;
        Gtk::TreeModelColumn<Glib::ustring> message;
    }
        model_columns;
       
    Gtk::TreeRow row;
       
    Glib::RefPtr<Gtk::ListStore> refModelColumns;
};

MyWindow::MyWindow()
:
    current_idx (0),
   
    messages ({
                "Little message",
                "This is a bit longer message",
                "You have just written a very long, long, long... message"
            }),

    bt_close ("Close"),
    bt_next ("Next"),

    refModelColumns (Gtk::ListStore::create (model_columns))
{
    set_title ("Col Width Test");
    set_border_width (5);
   
    treeview.set_model (refModelColumns);
    treeview.set_hexpand();
    treeview.set_vexpand();
   
    treeview.append_column ("Id", model_columns.id);
    treeview.append_column ("Message", model_columns.message);
   
    scrolled.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
    scrolled.add (treeview);
   
    buttonbox.set_layout (Gtk::BUTTONBOX_END);
    buttonbox.set_spacing (5);
    buttonbox.set_hexpand();
   
    buttonbox.pack_start (bt_close);
    buttonbox.pack_start (bt_next);
   
    bt_close.signal_clicked().connect (
        sigc::mem_fun (*this, &MyWindow::hide));
       
    bt_next.signal_clicked().connect (
        sigc::mem_fun (*this, &MyWindow::on_button_next_clicked));
   
    grid.set_row_spacing (5);
   
    grid.attach (scrolled, 0, 0, 1, 1);
    grid.attach (buttonbox, 0, 1, 1, 1);
   
    add (grid);
   
    fill_data();
   
    show_all_children();
}

void
MyWindow::fill_data()
{
    if (!refModelColumns->children().empty())
        refModelColumns->clear();
       
    if ((current_idx < 0) or
            (current_idx >= messages.size()))
        current_idx = 0;
       
    if (!messages.empty())
    {
        row = *(refModelColumns->append());
       
        row[model_columns.id] = current_idx;
        row[model_columns.message] = messages[current_idx];
    }
}

void
MyWindow::on_button_next_clicked()
{
    current_idx++;
   
    if ((current_idx < 0) or
            (current_idx >= messages.size()))
        current_idx = 0;
       
    fill_data();
}

MyWindow::~MyWindow()
{
}

int main (int argc, char *argv[])
{
    Glib::RefPtr<Gtk::Application> app =
        Gtk::Application::create (argc, argv, "org.gtkmm.example");
       
    MyWindow my_window;
   
    return app->run (my_window);
}

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Column grow preventing

Daniel Boles
I would start by seeing if the CellRendererText:wrap-* properties can help, if you haven't tried already:
https://developer.gnome.org/gtk3/stable/GtkCellRendererText.html#GtkCellRendererText--wrap-mode


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Column grow preventing

Glus Xof


2018-04-02 17:07 GMT+02:00 Daniel Boles <[hidden email]>:
I would start by seeing if the CellRendererText:wrap-* properties can help, if you haven't tried already:
https://developer.gnome.org/gtk3/stable/GtkCellRendererText.html#GtkCellRendererText--wrap-mode


After these lines

    treeview.append_column ("Id", model_columns.id);
    treeview.append_column ("Message", model_columns.message);

I inserted
   
    if (Gtk::CellRendererText * c_message =
            dynamic_cast<Gtk::CellRendererText *>(treeview.get_column_cell_renderer (1)))
        c_message->property_wrap_mode() = Pango::WRAP_WORD_CHAR;

and it doesn't run ...

 
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Column grow preventing

Daniel Boles
What does "it doesn't run" mean? Your program doesn't start? It starts but crashes? (or even, it does run but just doesn't change anything?) :P Assuming a crash, what does your debugger tell you about it?

Anyway, as the documentation says, that alone would not suffice: "This property has no effect unless the wrap-width property is set." But presumably that's not the only problem to solve right now.

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Column grow preventing

Glus Xof


2018-04-03 10:38 GMT+02:00 Daniel Boles <[hidden email]>:
What does "it doesn't run" mean? Your program doesn't start? It starts but crashes?

It means that compiles, starts, doesn't crash... but it doesn't show the desired effect of maintaining the treeview column size when "message" becomes longer.

(or even, it does run but just doesn't change anything?) :P Assuming a crash, what does your debugger tell you about it?

Anyway, as the documentation says, that alone would not suffice: "This property has no effect unless the wrap-width property is set." But presumably that's not the only problem to solve right now.
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Column grow preventing

Daniel Boles
and what about the next part of my message?

"Anyway, as the documentation says, that alone would not suffice: "This property has no effect unless the wrap-width property is set."

you only told it to wrap, but not *when* it should.


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list