le1nax
le1nax

Reputation: 37

How can I access on a widget at [i], stored in a Gtk::Box / Gtk::Grid?

I have a std::vector of Gtk::Boxes, that store widgets. Now, I want to access a certain widget in the Box at [i].

for(auto& it : layouts) {
        for(int i = 0; i < it->size(); ++i) {
            if(it->itemAt(i)->widget()) {
                it->itemAt(i)->widget()->setVisible((std::string(it->get_name())== StringID));
            }
        }
    }

layouts: std::vector holding Gtk::Boxes.
itemAt is a pseudo method, (QT method) to access Gtk::Box at (i).

Upvotes: 1

Views: 232

Answers (1)

BobMorane
BobMorane

Reputation: 4296

Gtk::Box is not the right abstraction. Every operation on widgets is relative to other widgets present in the container. If you want control over children at a specific location in your container, I would suggest moving from Gtk::Box to Gtk::Grid, which has special methods to do what you need. For example, you could use:

Widget* Gtk::Grid::get_child_at(int left,
                                int top 
                               )    

See the reference for more information.

Upvotes: 1

Related Questions