[英]GTK+ / Gtkmm, check if a notebook tab already exists, and create it only if it doesn't exist
I'm learning to use Gtkmm. 我正在学习使用Gtkmm。 Now I have got to make a window with a button which, when clicked, opens a "notebook" tab.
现在,我必须创建一个带有按钮的窗口,单击该按钮可以打开“笔记本”选项卡。 Now, I want to make it check if the tab already exists, and open the tab only if the tab doesn't exist.
现在,我要使其检查选项卡是否已存在,并仅在该选项卡不存在时才打开该选项卡。 Please, someone tell me if there is a way to do it with Gtkmm.
拜托,有人告诉我Gtkmm是否有办法。
Thanks in advance. 提前致谢。 My current code is the following:
我当前的代码如下:
#include <iostream>
#include <iomanip>
#include <gtkmm-3.0/gtkmm.h>
using namespace std;
class programa : public Gtk::Window
{
public:
//Constructor y destructor
programa();
~programa();
protected:
//Signal handlers:
void en_boton1();
//Child widgets:
Gtk::Grid w_grid;
Gtk::Button boton1;
Gtk::Notebook hojas;
Gtk::Label nombre1;
};
void programa::en_boton1()
{
hojas.append_page(nombre1, "Primera");
show_all_children();
}
programa::programa() : boton1(), boton2(), nombre1("pestaña 1"), nombre2("pestaña 2")
{
set_title("ventana");
maximize();
add(w_grid);
set_border_width(10);
boton1.add_pixlabel("info.xpm", "botoncito1");
w_grid.attach(boton1, 1 ,1 ,1 ,1);
boton1.signal_clicked().connect( sigc::mem_fun(*this,&programa::en_boton1 ) );
w_grid.attach(hojas, 1,2,4,1);
hojas.set_border_width(10);
show_all_children();
}
programa::~programa() {}
int main(int argc, char *argv[])
{
Gtk::Main paq(argc, argv);
programa principal;
//Shows the window and returns when it is closed.
Gtk::Main::run(principal);
return 0;
}
Gtk::Notebook::get_n_pages() and get_nth_page() should do what you need: https://developer.gnome.org/gtkmm/stable/classGtk_1_1Notebook.html#aee6987ef10d8e3afcc40824c53f4c1ad Gtk :: Notebook :: get_n_pages()和get_nth_page()应该可以满足您的要求: https : //developer.gnome.org/gtkmm/stable/classGtk_1_1Notebook.html#aee6987ef10d8e3afcc40824c53f4c1ad
But you'll need your own logic (probably after a dynamic_cast<>) to decide whether any of notebook pages are the one you are looking for. 但是,您将需要自己的逻辑(可能在dynamic_cast <>之后),以决定是否要查找任何笔记本页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.