Chinaunix首页 | 论坛 | 博客
  • 博客访问: 36024
  • 博文数量: 23
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 235
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-20 09:41
文章分类
文章存档

2011年(1)

2010年(2)

2009年(20)

我的朋友

分类:

2009-09-27 18:46:29

简单使用

Gtk::Entry m_entry;
m_entry.set_text("text");
m_entry.get_text();
m_entry.set_max_length();
m_entry.select_region(0, m_entry.get_text_length());
m_entry.set_editable();
m_entry.set_visibility();


在例子中还有其它的功能, 但在我的机子上不能编译:


m_entry.set_icon_from_stock(Gtk::Stock::FIND);
m_entry.signal_icon_press().connect(sigc::mem_fun(*this, &callback));

m_Entr.set_progress_fraction(double fraction);


还有一个高级功能是在输入的时候自动完成


ExampleWindow::ExampleWindow()
{
  Glib::RefPtr<Gtk::EntryCompletion> completion =
      Gtk::EntryCompletion::create();
  m_Entry.set_completion(completion);

  //Create and fill the completion's filter model

  Glib::RefPtr<Gtk::ListStore> refCompletionModel =
      Gtk::ListStore::create(m_Columns);
  completion->set_model(refCompletionModel);
    
    
  Gtk::TreeModel::Row row = *(refCompletionModel->append());
  row[m_Columns.m_col_id] = 1;
  row[m_Columns.m_col_name] = "Alan Zebedee";

  row = *(refCompletionModel->append());
  row[m_Columns.m_col_id] = 2;
  row[m_Columns.m_col_name] = "Adrian Boo";

  row = *(refCompletionModel->append());
  row[m_Columns.m_col_id] = 3;
  row[m_Columns.m_col_name] = "Bob McRoberts";

  row = *(refCompletionModel->append());
  row[m_Columns.m_col_id] = 4;
  row[m_Columns.m_col_name] = "Bob McBob";

  //Tell the completion what model column to use to

  //- look for a match (when we use the default matching, instead of

  // set_match_func().

  //- display text in the entry when a match is found.

  completion->set_text_column(m_Columns.m_col_name);

  //Add actions to the completion:

  //These are just extra items shown at the bottom of the list of possible

  //completions.


  //Remember them for later.

  typedef std::map<int, Glib::ustring> type_actions_map;
  type_actions_map m_CompletionActions;
  m_CompletionActions[0] = "use wizard";
  m_CompletionActions[1] = "browse for filename";

  for(type_actions_map::iterator iter = m_CompletionActions.begin();
          iter != m_CompletionActions.end(); ++iter)
  {
    int position = iter->first;
    Glib::ustring title = iter->second;
    completion->insert_action_text(title, position);
  }

  completion->signal_action_activated().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_completion_action_activated) );

}    
void ExampleWindow::on_completion_action_activated(int index)
{
  type_actions_map::iterator iter = m_CompletionActions.find(index);
  if(iter != m_CompletionActions.end()) //If it's in the map

  {
    Glib::ustring title = iter->second;
    std::cout << "Action selected: " << title << std::endl;
  }
}


阅读(686) | 评论(0) | 转发(0) |
0

上一篇:Gtk::Label

下一篇:Gtk::ClipBoard

给主人留下些什么吧!~~