Re: gtk_icon_theme_load_icon and GDK_SCALE=2 results in blurry icon


On Tue, 2017-10-03 at 20:13 +0200, infirit wrote:

See bug 765167 [1] it has an example in python how you can still use a
surface in the GtkIconView.  You should be able to translate this pretty
easily to C/C++.



Thanks a lot for the pointer. I was able to translate this into Gtkmm.
This fixes my issue, although I wish GTK would implement a proper
method for doing this.

This is the code, if anyone is interested:

class MainWindowIconView : public Gtk::IconView {

        Gtk::CellRendererPixbuf cell_renderer_pixbuf;  ///< Cell renderer for icons.
        Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > col_pixbuf;  ///< Model column
        // ...

                // ...

                // For high quality rendering with GDK_SCALE=2
                this->pack_start(cell_renderer_pixbuf, false);
                                sigc::mem_fun(this, &MainWindowIconView::on_cell_data_render));
                // ...

        /// Cell data renderer (needed for high quality icons in GDK_SCALE=2).
        /// We have to use Cairo surfaces, because pixbufs are scaled by GtkIconView.
        void on_cell_data_render(const Gtk::TreeModel::const_iterator& iter)
                Gtk::TreeRow row = *iter;
                Glib::RefPtr<Gdk::Pixbuf> pixbuf = row[col_pixbuf];

                // Gtkmm property_surface() doesn't work, so use plain C.
                cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(
                                pixbuf->gobj(), get_scale_factor(), get_window()->gobj());
                g_object_set(G_OBJECT(cell_renderer_pixbuf.gobj()), "surface", surface, NULL);

        // ...


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