Missatge de David Gasa i Castell <dgasac...@gmail.com> del dia dv., 16 d’abr. 2021 a les 17:54:
> I'm recently migrated to Gtk+-4 & Gtkmm-4.0, dued mainly to the > height-for-width trouble mentioned one week ago. > > The problem is that I don't see the way to verify that height-for-width > feature is back again in a treeview cell rows. > > If so, I need help to find out the changes that should be implemented in > the code attached below to see how the text fits above, in the same cell, > when the column size is been reduced. > > ---- code ----- > > #include <gtkmm.h> > #include <map> > > class MyWindow > : > public Gtk::Window > { > public: > > MyWindow(); > virtual ~MyWindow(); > > private: > > void fill_treeview(); > > void wrap_col (Gtk::TreeViewColumn *, Gtk::CellRendererText *); > > std::map<gint, Glib::ustring> messages; > > // Gtkmm widgets > > Gtk::Box box; > > Gtk::TreeView treeview; > > Gtk::Separator separator; > Gtk::Button button; > > class ModelColumns > : > public Gtk::TreeModel::ColumnRecord > { > public: > > ModelColumns() > { > add (id); > add (message); > } > > Gtk::TreeModelColumn<gint> id; > Gtk::TreeModelColumn<Glib::ustring> message; > } > model_cols; > > Glib::RefPtr<Gtk::ListStore> refListStore; > > Gtk::TreeRow row; > }; > > MyWindow::MyWindow() > : > box (Gtk::Orientation::VERTICAL, 5), > button ("Close"), > > messages ({ > {1, "Message: one"}, > {2, "Message: one two"}, > {3, "Message: one two three"}, > {4, "Message: one two three four"} > }), > > refListStore (Gtk::ListStore::create (model_cols)) > { > set_title ("MyWindow"); > > treeview.set_model (refListStore); > > treeview.append_column ("Id.", model_cols.id); > > gint m_col = > treeview.append_column ("Message", model_cols.message)-1; > > if (Gtk::TreeViewColumn * cl_message = treeview.get_column (m_col)) > { > cl_message->connect_property_changed ("width", > sigc::bind (sigc::mem_fun (*this, &MyWindow::wrap_col), cl_message, > dynamic_cast<Gtk::CellRendererText *>(treeview.get_column_cell_renderer > (m_col)))); > } > > treeview.set_vexpand(); > treeview.set_margin (10); > > button.set_margin (10); > > box.append (treeview); > box.append (separator); > box.append (button); > > button.signal_clicked().connect (sigc::mem_fun (*this, > &Gtk::Widget::hide)); > > set_child (box); > > fill_treeview(); > } > > void > MyWindow::fill_treeview() > { > if (!refListStore->children().empty()) > refListStore->clear(); > > for (auto & it : messages) > { > row = *(refListStore->append()); > > row[model_cols.id] = it.first; > row[model_cols.message] = it.second; > } > } > > void > MyWindow::wrap_col ( > Gtk::TreeViewColumn * _column, Gtk::CellRendererText * _cell_renderer) > { > _cell_renderer->property_wrap_mode() = Pango::WrapMode::WORD; > > gint width = _column->get_width(); > _cell_renderer->property_wrap_width() = width; > } > > MyWindow::~MyWindow() > { > } > > int main (int argc, char* argv[]) > { > auto app = Gtk::Application::create ("org.gtkmm"); > return app->make_window_and_run<MyWindow>(argc, argv); > } > > -- > David Gasa i Castell > > Linux User #488832 > By these changes seems to be possible to reduce the column size and the text breaks fine (word wrapping)... if (Gtk::TreeViewColumn * cl_message = treeview.get_column (m_col)) { cl_message->set_fixed_width (0); cl_message->set_min_width (0); cl_message->connect_property_changed ("width", sigc::bind (sigc::mem_fun (*this, &MyWindow::wrap_col), cl_message, dynamic_cast<Gtk::CellRendererText *>(treeview.get_column_cell_renderer (m_col)))); } But the rest of text line is hidden, getting something like, ================= Id Messages ================= 1 Message: one ================= 2 Message: one ================= 3 Message: one ================= 4 Message: one ================= How could I do to get as follows ? ================= Id Messages ================= 1 Message: one ================= 2 Message: one two ================= 3 Message: one two three ================= 4 Message: one two three four ================= -- David Gasa i Castell Linux User #488832
_______________________________________________ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list