Re: Gtk::EntryCompletion persists in default behavior after connecting
- From: Jason Curole <jcurole gmail com>
- To: gtkmm-list gnome org
- Subject: Re: Gtk::EntryCompletion persists in default behavior after connecting
- Date: Sat, 9 May 2009 13:25:02 +0545
I know this unanswered thread is quite old (so old that I cannot
figure out how to directly reply to the original message), but I
recently struggled with this same issue and rather serendipitously
stumbled upon the solution. So, for future newbies like me and
Krzesimir if he is still listening, the problem for me (and I believe
for the code below as well) is that you have to tell 'connect' to
connect your signal handler to the signal before it connects default
signal handler. For the example below, that is done as:
m_ref_name_compl->signal_match_selected().connect(sigc::mem_fun(*this,
&ComplWindow::on_match_selected), false);
Note the false as the second argument to connect. By default this
argument is true meaning connect after default. And be certain to
return true so the default handler is not called.
Find out more at:
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1SignalProxy0.html#d6c26072ea85fe6e61895b0750421e92
Jason
---------------Primary post below------------------
Hi,
I'm using gtkmm 2.12.7 (as in Debian Sid).
I have testing program which contains only of 2 Gtk::Entries. In one
user should enter somebody's name and in a second - somebody's surname.
I wanted it to work that way, when user selects a name in name entry,
its corresponding surname should appear in surname entry.
Example:
User has entered "A" in name entry, so four names appear - Arturo,
Andrzej, Anthony and Aleksander. User selects Anthony and this name
appears in name entry and in the same time in surname entry "Burgess"
word appears.
I set EntryCompletion for each entry and a list of names/surnames
appears while entering data to entry. So it works. Each EntryCompletion
uses the same TreeModel, but with different text columns. But when I
want to connect my custom function to EntryCompletion's
signal_match_selected (or to any other its signals), program still uses
a default behavior. I was just following instructions in documentation.
Making a class inheriting from Gtk::EntryCompletion and overriding a
on_match_selected (like in Gtk::Util::MultiEntryCompletion) does not
work for me, because in overriden function I need access to both entries
to set their texts.
Am I doing something wrong? I'd appreciate any help.
Here is my code (cut for brevity):
BEGIN CODE BLOCK
#include <iostream>
#include "complwindow.h"
ComplWindow::ComplWindow(BaseObjectType* cobject,
Glib::RefPtr<Gnome::Glade::Xml> xml) :
Gtk::Window(cobject),
m_ref_glade(xml),
m_name_entry(dynamic_cast<Gtk::Entry*>(m_ref_glade->get_widget("name_entry"))),
m_surname_entry(dynamic_cast<Gtk::Entry*>(m_ref_glade->get_widget("surname_entry"))),
m_ref_name_compl(Gtk::EntryCompletion::create()),
m_ref_surname_compl(Gtk::EntryCompletion::create()),
m_model_columns(),
m_ref_tree_model(Gtk::ListStore::create(m_model_columns))
{
Gtk::TreeModel::Row data_row = *(m_ref_tree_model->append());
data_row[m_model_columns.m_id] = 1;
data_row[m_model_columns.m_name] = Glib::ustring("Bram");
data_row[m_model_columns.m_surname] = Glib::ustring("Stoker");
data_row = *(m_ref_tree_model->append());
data_row[m_model_columns.m_id] = 2;
data_row[m_model_columns.m_name] = Glib::ustring("Robert");
data_row[m_model_columns.m_surname] = Glib::ustring("Jordan");
// and so on.
m_ref_name_compl->set_model(m_ref_tree_model);
m_ref_surname_compl->set_model(m_ref_tree_model);
m_ref_name_compl->set_text_column(m_model_columns.m_name);
m_ref_surname_compl->set_text_column(m_model_columns.m_surname);
m_name_entry->set_completion(m_ref_name_compl);
m_surname_entry->set_completion(m_ref_surname_compl);
m_ref_name_compl->signal_match_selected().connect(sigc::mem_fun(*this,
&ComplWindow::on_match_selected));
}
bool
ComplWindow::on_match_selected(const Gtk::TreeModel::iterator& iter)
{
Glib::ustring name((*iter)[m_model_columns.m_name]);
Glib::ustring surname((*iter)[m_model_columns.m_surname]);
std::cout << name << " " << surname << std::endl;
m_name_entry->set_text(name);
m_surname_entry->set_text(surname);
return true;
}
END CODE BLOCK
I attached an archive with whole source code (glade file included).
Thanks,
Krzesimir
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]