我使用库 gtkmm 创建了一个笔记本,但我无法打开一些新选项卡。这是我的代码:
有三个文件:
主文件
#include <gtkmm/main.h>
#include "win.hpp"
int main(int argc, char *argv[]){
Gtk::Main app(argc, argv);
Win win;
Gtk::Main::run(win);
return EXIT_SUCCESS;
}
赢.hpp:
#ifndef DEF_WIN
#define DEF_WIN
#include <gtkmm.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <sstream>
class Win : public Gtk::Window{
public:
Win();
private:
Gtk::Notebook m_notebook;
Gtk::Grid m_grid1;
Gtk::Grid m_grid2;
};
#endif
这是最后一个文件:
#include "win.hpp"
Win::Win(){
maximize();
set_title("Test");
Gtk::VBox *boxV = Gtk::manage(new Gtk::VBox(false,0));
add(*boxV);
Gtk::MenuBar *barreMenu = Gtk::manage(new Gtk::MenuBar);
boxV->pack_start(*barreMenu, Gtk::PACK_SHRINK);
Gtk::MenuItem *menuItemFile = Gtk::manage(new Gtk::MenuItem("_File",true));
barreMenu->append(*menuItemFile);
Gtk::Menu *menuFile = Gtk::manage(new Gtk::Menu);
menuItemFile->set_submenu(*menuFile);
Gtk::ImageMenuItem *menuNew = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::NEW));
menuFile->append(*menuNew);
menuNew->signal_activate().connect([this]() {
m_notebook.append_page(m_grid1,"Hello");
});
m_notebook.popup_enable();
Gtk::Grid* grid1 = Gtk::manage(new Gtk::Grid());
grid1->set_border_width(0);
grid1->set_row_spacing(0);
Gtk::Label *title = Gtk::manage(new Gtk::Label());
title->set_markup("<b><span size='xx-large'>Welcome !");
title->set_hexpand(true);
grid1->attach(*title,0,0,10,1);
Gtk::Button *commencer = Gtk::manage(new Gtk::Button("Start"));
grid1->attach(*commencer,4,7,2,3);
commencer->set_hexpand(true);
commencer->signal_clicked().connect([this]() {
m_notebook.append_page(m_grid2,"Hey");
});
m_notebook.append_page(*grid1, "New worksheet");
boxV->pack_start(m_notebook);
show_all();
}
代码编译没有任何问题。但是当我执行代码并单击“开始”或“新建”时,我没有看到新选项卡,而且我不知道为什么,因为我在信号中输入了这个:
m_notebook.append_page(m_grid1,"Hello");
还有这个:
m_notebook.append_page(m_grid2,"Hey");