【问题标题】:How can I access on a widget at [i], stored in a Gtk::Box / Gtk::Grid?如何访问存储在 Gtk::Box / Gtk::Grid 中的 [i] 处的小部件?
【发布时间】:2021-06-04 16:33:00
【问题描述】:

我有一个 Gtk::Boxes 的 std::vector,用于存储小部件。现在,我想在 [i] 处访问 Box 中的某个小部件。

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));
            }
        }
    }

布局:std::vector 持有 Gtk::Boxes。
itemAt 是一个伪方法,(QT 方法)在 (i) 处访问 Gtk::Box。

【问题讨论】:

    标签: user-interface widget gtkmm


    【解决方案1】:

    Gtk::Box 不是正确的抽象。小部件上的每个操作都与容器中存在的其他小部件相关。如果您想控制容器中特定位置的孩子,我建议从Gtk::Box 移动到Gtk::Grid,它有特殊的方法可以满足您的需要。例如,您可以使用:

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

    更多信息请参见the reference

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2014-04-11
      • 1970-01-01
      相关资源
      最近更新 更多