Align TreeModel::Row

hi, I’m using gtkmm 4 to display a list with images.
I’m using Gtk::TreeView with Gtk::TreeModel.

image

I need to set the row’ alignment but Gtk::TreeModel::Row doesn’t have such API.
Can anyone suggest a way to pin the checkmark to the row end?

IconsList.h

class IconsList : public Gtk::ScrolledWindow
{
public:
    IconsList();
    void AddRow(const char *name);

private:
    class ModelColumns : public Gtk::TreeModel::ColumnRecord
    {
    public:
        ModelColumns()
        {
            add(_coloumnName);
            add(_pixbuf);
        }

        Gtk::TreeModelColumn<Glib::ustring> _coloumnName;
        Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> _pixbuf;
    };
    ModelColumns _columns;

    Gtk::TreeView _treeView;
    Glib::RefPtr<Gtk::ListStore> _refTreeModel;
    Glib::RefPtr<Gdk::Pixbuf> _checkIcon;
};

IconsList .cpp:
IconsList::IconsList()
{
        set_child(_treeView);
        set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC);

        // Create the Tree model:
        _refTreeModel = Gtk::ListStore::create(_columns);
        _treeView.set_model(_refTreeModel);

        // All the items to be reordered with drag-and-drop:
        _treeView.set_headers_visible(true);
        _treeView.set_halign(Gtk::Align::FILL);
        _treeView.set_valign(Gtk::Align::FILL);
        _treeView.set_expand(true);

        _treeView.append_column("Name", _columns._coloumnName);
        Gtk::TreeViewColumn* column = CreateManaged<Gtk::TreeViewColumn>("Image", _columns._pixbuf); 
        column->set_alignment(Gtk::Align::END);
        _treeView.append_column(*column););
        // icon for selected row
        _checkIcon = Gdk::Pixbuf::create_from_file(CHECKMARK_FILE_NAME);

        show();
    }
}

void IconsList::AddRow(const char *name)
{
    Gtk::TreeModel::Row row = *(_refTreeModel->append());
    row[_columns._coloumnName] = name;
}

I think the best way is to have a middle column that consumes all the space by setting expand to true. That how we did it in a fairly complex TreeView.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.