Re: List view callback
pcr <[email protected]> Sat, 27 Jul 2019 15:16:34 -0600
| Newsgroups | gmane.editors.abiword.user |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------85F842DABB15DCC704B9848A
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
I solved my problem by adhering more closely to the textview example.
My corrected code is attached. Thank you in any event. PCR
On 7/26/19 8:33 PM, pcr wrote:
> I am having difficulty calling a routine when a row in my list view is
> clicked. My example code is attached. I get a compile error saying:
> error: ‘m_Columns’ does not name a type; did you mean ‘ModelColumns’?
> m_Columns.signal_listview_row_activated().connect( sigc::mem_fun(*this,
> ^~~~~~~~~
> ModelColumns
>
> But ModelColumns does not work either. Any help is appreciated greatly!
>
--------------85F842DABB15DCC704B9848A
Content-Type: text/x-c++src;
name="test.cc"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="test.cc"
//compile me with: g++ -g -Wall -o test test.cc `(pkg-config --cflags --libs gtkmm-3.0)`
#include <gtkmm.h>
#include <iostream>
#include <gtkmm/application.h>
class ExampleWindow : public Gtk::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
protected:
//Signal handlers:
void on_treeview_row_activated(const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn* column);
//Tree model columns:
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{ add(m_col_id); add(m_col_name);}
Gtk::TreeModelColumn<unsigned int> m_col_id;
Gtk::TreeModelColumn<Glib::ustring> m_col_name;
};
ModelColumns m_Columns;
//Child widgets:
Gtk::Box m_VBox;
Gtk::ScrolledWindow m_ScrolledWindow;
Gtk::TreeView m_TreeView;
Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;
};
ExampleWindow::ExampleWindow()
: m_VBox(Gtk::ORIENTATION_VERTICAL)
{
set_title("Gtk::TreeView simplified with callback");
set_border_width(5);
set_default_size(400, 200);
add(m_VBox);
//Add the TreeView, inside a ScrolledWindow
m_ScrolledWindow.add(m_TreeView);
//Only show the scrollbars when they are necessary:
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
m_VBox.pack_start(m_ScrolledWindow);
//Create the Tree model:
m_refTreeModel = Gtk::TreeStore::create(m_Columns);
m_TreeView.set_model(m_refTreeModel);
//Fill the TreeView's model
Gtk::TreeModel::Row row = *(m_refTreeModel->append());
row[m_Columns.m_col_id] = 1;
row[m_Columns.m_col_name] = "Billy Bob";
//Add the TreeView's view columns:
m_TreeView.append_column("ID", m_Columns.m_col_id);
m_TreeView.append_column("Name", m_Columns.m_col_name);
//Conection from signal to callback
m_TreeView.signal_row_activated().connect( sigc::mem_fun(*this,
&ExampleWindow::on_treeview_row_activated));
show_all_children();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_treeview_row_activated(const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn*)
{
//Why is this not being called when the row is clicked?????
std::cout << "row activated" << std::endl;
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc,argv, "org.pcrt.example");
ExampleWindow window;
return app->run(window);
}
--------------85F842DABB15DCC704B9848A--
-----------------------------------------------
To unsubscribe from this list, send a message to
[email protected] with the word
unsubscribe in the message body.