如何在gtkmm-2.4中创建一个输入字段(textfield)?
这是一个代码片段,显示了一个容纳三个按钮的容器。我想知道如何添加一个入口字段。我在gtkmm中找不到任何类。
headerfile:
#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
#define GTKMM_EXAMPLE_HELLOWORLD_H
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/window.h>
class HelloWorld : public Gtk::Window
{
public:
HelloWorld();
virtual ~HelloWorld();
protected:
// Signal handlers:
// Our new improved on_button_clicked(). (see below)
void on_button_clicked(Glib::ustring data);
// Child widgets:
Gtk::HBox m_box1;
Gtk::Button m_button1, m_button2, m_button3;
};
#endif // GTKMM_EXAMPLE_HELLOWORLD_H
CPP-文件:的
#include "helloworld.h"
#include <iostream>
HelloWorld::HelloWorld()
: m_button1("Button 1"),
m_button2("Button 2"),
m_button3("Button 3")
{
set_title("Hello Buttons!");
set_border_width(10);
add(m_box1);
m_button1.signal_clicked().connect(sigc::bind<Glib::ustring>(
sigc::mem_fun(*this, &HelloWorld::on_button_clicked), "button 1"));
m_box1.pack_start(m_button1);
m_button1.show();
m_button2.signal_clicked().connect(sigc::bind<-1, Glib::ustring>(
sigc::mem_fun(*this, &HelloWorld::on_button_clicked), "button 2"));
m_box1.pack_start(m_button2);
m_button2.show();
m_button3.signal_clicked().connect(sigc::bind<-1, Glib::ustring>(
sigc::mem_fun(*this, &HelloWorld::on_button_clicked), "button 3"));
m_box1.pack_start(m_button3);
m_button3.show();
m_box1.show();
}
HelloWorld::~HelloWorld()
{
}
void HelloWorld::on_button_clicked(Glib::ustring data)
{
std::cout << "Hello World - " << data << " was pressed" << std::endl;
}
答案 0 :(得分:1)
您需要使用Gtk :: Entry: