繁体   English   中英

GTK + / Gtkmm,检查笔记本选项卡是否已存在,并仅在不存在时创建它

[英]GTK+ / Gtkmm, check if a notebook tab already exists, and create it only if it doesn't exist

我正在学习使用Gtkmm。 现在,我必须创建一个带有按钮的窗口,单击该按钮可以打开“笔记本”选项卡。 现在,我要使其检查选项卡是否已存在,并仅在该选项卡不存在时才打开该选项卡。 拜托,有人告诉我Gtkmm是否有办法。
提前致谢。 我当前的代码如下:

#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()和get_nth_page()应该可以满足您的要求: https : //developer.gnome.org/gtkmm/stable/classGtk_1_1Notebook.html#aee6987ef10d8e3afcc40824c53f4c1ad

但是,您将需要自己的逻辑(可能在dynamic_cast <>之后),以决定是否要查找任何笔记本页面。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM