2

我有一个带有垂直框布局的窗口。在布局中,我放置了三个小部件:菜单栏、笔记本和状态栏。菜单栏和状态栏正常工作。但是笔记本不能按预期工作:无论我添加多少标签,它既不会显示任何内容,也不会附加标签(即:_notebook->get_n_pages() 始终为 1)。

添加标签的代码:

Gtk::Label label;
Gtk::TreeView widget;
Gtk::TreeModelColumnRecord colrec;

// Columns are added here to 'colrec'

Glib::RefPtr<Gtk::ListStore> store = Gtk::ListStore::create(colrec);

widget.set_model(store);

_notebook->append_page(widget, label);

我错过了什么吗?UI 是从一个 glade 文件加载的。它在 Glade 中也显示错误,因为我删除了默认选项卡。

4

1 回答 1

1

我不是 100% 确定这是罪魁祸首,但首先你Gtk::TreeView会被摧毁。尝试gtkmm 管理/添加 vs 智能指针: .

#include <gtkmm.h>
#include <iostream>

void add(Gtk::Notebook& _notebook)
{
    Gtk::Label label;
    auto  widget = Gtk::manage(new Gtk::TreeView());
    Gtk::TreeModelColumnRecord colrec;

    // Columns are added here to 'colrec'

    Glib::RefPtr<Gtk::ListStore> store = Gtk::ListStore::create(colrec);

    widget->set_model(store);

    _notebook.append_page(*widget, label);
}

int main()
{
    auto Application = Gtk::Application::create();
    Gtk::Window window;

    Gtk::Notebook notebook;
    add(notebook);
    add(notebook);

    window.add(notebook);
    std::cout<<notebook.get_n_pages()<<std::endl;
    window.show_all();
    Application->run(window);
    return 0;
}
于 2017-01-16T12:54:14.463 回答