Gtk::Notebook 未显示
Gtk::Notebook not showing
我有一个 window 的垂直框布局。在布局中,我放置了三个小部件:菜单栏、笔记本和状态栏。菜单栏和状态栏工作正常。但是笔记本没有按预期工作:无论我添加多少标签,它既不会显示任何内容也不会附加标签(即:_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 中也显示错误,因为我删除了默认选项卡。
我不是 100% 确定这是罪魁祸首,但首先你的 Gtk::TreeView
被摧毁了。试试 gtkmm manage/add vs smart pointers:.
#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;
}
我有一个 window 的垂直框布局。在布局中,我放置了三个小部件:菜单栏、笔记本和状态栏。菜单栏和状态栏工作正常。但是笔记本没有按预期工作:无论我添加多少标签,它既不会显示任何内容也不会附加标签(即:_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 中也显示错误,因为我删除了默认选项卡。
我不是 100% 确定这是罪魁祸首,但首先你的 Gtk::TreeView
被摧毁了。试试 gtkmm manage/add vs smart pointers:.
#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;
}