Re: Problem with sorting ColumnView
Thanks! Somehow I got the impression that the ColumnView would construct SortListModels on its own, but looking back at the documentation I'm not sure where I heard that. Here is a working solution: #include > #include > > class MyWindow : public Gtk::Window { > private: > > Gtk::ColumnView _columnView; > > public: > > MyWindow() { > > auto listModel = Gio::ListStore::create(); > auto sortListModel = Gtk::SortListModel::create(listModel, > _columnView.get_sorter()); > _columnView.set_model(Gtk::SingleSelection::create(sortListModel)); > > auto files = Gio::File::create_for_path(".")->enumerate_children(); > Glib::RefPtr fileInfo; > while ((fileInfo = files->next_file())) { > > listModel->append(Gio::File::create_for_path(fileInfo->get_name())); > } > > auto factory = Gtk::SignalListItemFactory::create(); > factory->signal_setup().connect([](auto listItem) { > listItem->set_child(*Gtk::make_managed("_", > Gtk::Align::START)); > }); > factory->signal_bind().connect([](auto listItem) { > auto data = > std::dynamic_pointer_cast(listItem->get_item()); > auto label = dynamic_cast(listItem->get_child()); > if (data && label) > label->set_text(data->get_path()); > }); > > auto column = Gtk::ColumnViewColumn::create("File Paths", factory); > column->set_sorter(Gtk::StringSorter::create( > Gtk::ClosureExpression::create([](auto > item) { > auto data = std::dynamic_pointer_cast(item); > return data->get_basename(); > }) > )); > _columnView.append_column(column); > > _columnView.sort_by_column(column, Gtk::SortType::ASCENDING); > set_child(_columnView); > }; > }; > > int main(int argc, char *argv[]) { > auto app = Gtk::Application::create("org.gtkmm.examples.base"); > return app->make_window_and_run(argc, argv); > } > I appreciate your help! Jackson On Tue, Aug 23, 2022 at 9:38 PM Andrew Potter wrote: > The documentation at > https://docs.gtk.org/gtk4/method.ColumnView.get_sorter.html suggests you > need a SortListModel > > On Tue, Aug 23, 2022 at 4:32 AM Jackson Campolattaro via gtkmm-list < > gtkmm-list@gnome.org> wrote: > >> Hello, >> >> I'm trying to use the Gtk ColumnView to show a custom ListModel in sorted >> order. I noticed that when I set a simple sorter for a column and then sort >> by that column, the order isn't changed. The UI allows me to switch between >> ascending and descending, but doing so doesn't reverse the list. >> >> I've created a simplified example, which is supposed to show the file >> paths in the current directory in alphabetical order, but doesn't: >> >> #include >>> #include >>> >>> class MyWindow : public Gtk::Window { >>> private: >>> >>> Glib::RefPtr> _listModel; >>> Glib::RefPtr _selectionModel; >>> >>> Gtk::ColumnView _columnView; >>> >>> public: >>> MyWindow() { >>> >>> _listModel = Gio::ListStore::create(); >>> _selectionModel = Gtk::SingleSelection::create(_listModel); >>> _columnView.set_model(_selectionModel); >>> >>> auto files = >>> Gio::File::create_for_path(".")->enumerate_children(); >>> Glib::RefPtr fileInfo; >>> while ((fileInfo = files->next_file())) { >>> >>> _listModel->append(Gio::File::create_for_path(fileInfo->get_name())); >>> } >>> >>> auto _factory = Gtk::SignalListItemFactory::create(); >>> _factory->signal_setup().connect([](auto listItem) { >>> >>> listItem->set_child(*Gtk::make_managed("Placeholder!")); >>> }); >>> _factory->signal_bind().connect([](auto listItem) { >>> auto data = >>> std::dynamic_pointer_cast(listItem->get_item()); >>> auto label = dynamic_cast>> *>(listItem->get_child()); >>> if (data && label) { >>> label->set_text(data->get_path()); >>> label->set_xalign(0); >>> } >>> }); >>> >>> auto column = Gtk::ColumnViewColumn::create("File Paths", >>> _factory); >>> _columnView.append_column(column); >>> >>> column->set_sorter(Gtk::StringSorter::create( >>> Gtk::ClosureExpression::create([](auto >>> item) { >>> auto data = >>> std::dynamic_pointer_cast(item); >>> return data->get_path(); >>> }) >>> )); >>> _columnView.sort_by_column(column, Gtk::SortType::ASCENDING); >>> >>> set_child(_columnView); >>> }; >>> }; >>> >>> int main(int argc, char *argv[]) { >>> auto app = Gtk::Application::create("org.gtkmm.examples.base"); >>> return app->make_window_and_run(argc, argv); >>> } >>> >> >> Perhaps this is a bug, but before I report it I wanted to make sure I'm >> not doing something wrong. >> >> Thanks, >> >> Jackson >> _
Re: Problem with sorting ColumnView
The documentation at https://docs.gtk.org/gtk4/method.ColumnView.get_sorter.html suggests you need a SortListModel On Tue, Aug 23, 2022 at 4:32 AM Jackson Campolattaro via gtkmm-list < gtkmm-list@gnome.org> wrote: > Hello, > > I'm trying to use the Gtk ColumnView to show a custom ListModel in sorted > order. I noticed that when I set a simple sorter for a column and then sort > by that column, the order isn't changed. The UI allows me to switch between > ascending and descending, but doing so doesn't reverse the list. > > I've created a simplified example, which is supposed to show the file > paths in the current directory in alphabetical order, but doesn't: > > #include >> #include >> >> class MyWindow : public Gtk::Window { >> private: >> >> Glib::RefPtr> _listModel; >> Glib::RefPtr _selectionModel; >> >> Gtk::ColumnView _columnView; >> >> public: >> MyWindow() { >> >> _listModel = Gio::ListStore::create(); >> _selectionModel = Gtk::SingleSelection::create(_listModel); >> _columnView.set_model(_selectionModel); >> >> auto files = >> Gio::File::create_for_path(".")->enumerate_children(); >> Glib::RefPtr fileInfo; >> while ((fileInfo = files->next_file())) { >> >> _listModel->append(Gio::File::create_for_path(fileInfo->get_name())); >> } >> >> auto _factory = Gtk::SignalListItemFactory::create(); >> _factory->signal_setup().connect([](auto listItem) { >> >> listItem->set_child(*Gtk::make_managed("Placeholder!")); >> }); >> _factory->signal_bind().connect([](auto listItem) { >> auto data = >> std::dynamic_pointer_cast(listItem->get_item()); >> auto label = dynamic_cast> *>(listItem->get_child()); >> if (data && label) { >> label->set_text(data->get_path()); >> label->set_xalign(0); >> } >> }); >> >> auto column = Gtk::ColumnViewColumn::create("File Paths", >> _factory); >> _columnView.append_column(column); >> >> column->set_sorter(Gtk::StringSorter::create( >> Gtk::ClosureExpression::create([](auto >> item) { >> auto data = >> std::dynamic_pointer_cast(item); >> return data->get_path(); >> }) >> )); >> _columnView.sort_by_column(column, Gtk::SortType::ASCENDING); >> >> set_child(_columnView); >> }; >> }; >> >> int main(int argc, char *argv[]) { >> auto app = Gtk::Application::create("org.gtkmm.examples.base"); >> return app->make_window_and_run(argc, argv); >> } >> > > Perhaps this is a bug, but before I report it I wanted to make sure I'm > not doing something wrong. > > Thanks, > > Jackson > ___ > gtkmm-list mailing list > gtkmm-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtkmm-list > ___ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list
Re: initialize `background-image` with a resource file
On Tue, Aug 23, 2022 at 10:44 AM Master via gtkmm-list wrote: > The problem is that I dont know how to tell the `background-image` inside > the style provider to "get the image from resource" instead of "file" > please help me. > Hello, You can set background image to a resource like: background-image: url("resource:///org/custom/example/sonbg.jpg"); Of course, you must define a gresource xml (Here, I've used the gresource prefix org/custom/example, but you will want to use your own namespace), compile it with glib-compile-resources and include it in your build system appropriately. This is detailed in the GResource documentation at https://docs.gtk.org/gio/struct.Resource.html or in the gtkmm documentation at https://gnome.pages.gitlab.gnome.org/glibmm/classGio_1_1Resource.html#details I have a toy application on github that does this if you need a more concrete example. The C++ code in https://github.com/talisein/mikuexpocountdown/blob/main/src/window.h loads the CSS from a resource, and that css references the gresources in https://github.com/talisein/mikuexpocountdown/tree/main/res ___ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list
initialize `background-image` with a resource file
in my gtkmm app i have a label that has a background image thanks to css provider. like this: ``` MainWindow::MainWindow(): Mylabel(Hello) { provider = Gtk::CssProvider::create(); provider->load_from_data( "#LogoLabel{" //"color:#80;" //"color:#5485ae;" "color:#0075ff;" "}" "#PleaseHitKeyLbl{" "background-color:#337a;" "font-size:20px;" "}" "#BackgroundImage{" "background-image:url(\"file:///home/ali/Desktop/sonbg.jpg\");" "background-size:100% 100%;" "opacity:0.3;" "}" ); MyLabel.set_name("BackgroundImage"); MyLabel.get_style_context()->add_provider(provider, 1); } ``` The problem is that I dont know how to tell the `background-image` inside the style provider to "get the image from resource" instead of "file" please help me. Regards. ___ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list
Problem with sorting ColumnView
Hello, I'm trying to use the Gtk ColumnView to show a custom ListModel in sorted order. I noticed that when I set a simple sorter for a column and then sort by that column, the order isn't changed. The UI allows me to switch between ascending and descending, but doing so doesn't reverse the list. I've created a simplified example, which is supposed to show the file paths in the current directory in alphabetical order, but doesn't: #include > #include > > class MyWindow : public Gtk::Window { > private: > > Glib::RefPtr> _listModel; > Glib::RefPtr _selectionModel; > > Gtk::ColumnView _columnView; > > public: > MyWindow() { > > _listModel = Gio::ListStore::create(); > _selectionModel = Gtk::SingleSelection::create(_listModel); > _columnView.set_model(_selectionModel); > > auto files = Gio::File::create_for_path(".")->enumerate_children(); > Glib::RefPtr fileInfo; > while ((fileInfo = files->next_file())) { > > _listModel->append(Gio::File::create_for_path(fileInfo->get_name())); > } > > auto _factory = Gtk::SignalListItemFactory::create(); > _factory->signal_setup().connect([](auto listItem) { > > listItem->set_child(*Gtk::make_managed("Placeholder!")); > }); > _factory->signal_bind().connect([](auto listItem) { > auto data = > std::dynamic_pointer_cast(listItem->get_item()); > auto label = dynamic_cast(listItem->get_child()); > if (data && label) { > label->set_text(data->get_path()); > label->set_xalign(0); > } > }); > > auto column = Gtk::ColumnViewColumn::create("File Paths", > _factory); > _columnView.append_column(column); > > column->set_sorter(Gtk::StringSorter::create( > Gtk::ClosureExpression::create([](auto > item) { > auto data = std::dynamic_pointer_cast(item); > return data->get_path(); > }) > )); > _columnView.sort_by_column(column, Gtk::SortType::ASCENDING); > > set_child(_columnView); > }; > }; > > int main(int argc, char *argv[]) { > auto app = Gtk::Application::create("org.gtkmm.examples.base"); > return app->make_window_and_run(argc, argv); > } > Perhaps this is a bug, but before I report it I wanted to make sure I'm not doing something wrong. Thanks, Jackson ___ gtkmm-list mailing list gtkmm-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtkmm-list