创建输入字段
Creating an entryfield
如何在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-file:
#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;
}
您需要使用Gtk::Entry:
- https://developer.gnome.org/gtkmm/unstable/classGtk_1_1Entry.html
- https://developer.gnome.org/gtkmm-tutorial/unstable/sec-text-entry.html.en
或Gtk:: TextView:
- https://developer.gnome.org/gtkmm/stable/classGtk_1_1TextView.html
- https://developer.gnome.org/gtkmm-tutorial/stable/chapter-textview.html.en
相关文章:
- 将结构字段的类型展开为可变模板参数
- 将位字段导出到数组
- 为了方便起见,我应该避免公开私有字段变量吗
- 当字段可以为null时,如何使用C++接口在Avro中写入数据
- 在java中读取c++字节的位字段
- 链接器找不到在虚拟类 c++ 中访问的静态字段的符号
- 私有字段对象与私有继承?
- 如何检查字段中输入的数字是否重复
- 确定输入"conscalc: calc"的类型时出错。不能联合编码器。具有不同字段集的结构类型
- 我如何一遍又一遍地向用户提问,直到他们输入正确的值字段?
- 如何在 中输入记录的一个字段时搜索记录
- 使数据输入字段记住其值,从一次运行到下一次运行
- 在不模拟Ctrl+V的情况下将数据粘贴到任何应用程序输入字段中.Windows c++
- 如何创建一个包含用户在程序中输入的 3 个字段的结构
- CDHtmlDialog将焦点设置在输入字段上
- 创建输入字段
- 将内存数据PTR映射到qt输入字段
- 我如何让一个输入语句重复,直到用户选择的字段数完成
- 用户界面-Adobe Adam and Eve,C++:如何创建可点击按钮、轨迹栏、文本输入字段和图像
- 如何从QWebView的输入字段中获取值