//helloworld.h
#include <gtkmm/window.h>
#include <gtkmm/fixed.h>
class HelloWorld : public Gtk::Window
{
public:
HelloWorld();
virtual ~HelloWorld();
protected:
//Signal handlers:
void on_button_clicked();
//Member widgets:
Gtk::Button m_button;
Gtk::Button m_btn;
public:
bool on_delete_event(GdkEventAny* event); //Widget的虚函数
Gtk::Fixed m_fix;
};
#endif // GTKMM_EXAMPLE_HELLOWORLD_H
//helloworld.cc
#include "helloworld.h"
#include <iostream>
#include <gtkmm.h>
HelloWorld::HelloWorld()
: m_button("Hello World") // creates a new button with label "Hello World".
{
// Sets the border width of the window.
set_border_width(10);
// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method defined below.
m_button.signal_clicked().connect(sigc::mem_fun(*this,
&HelloWorld::on_button_clicked));
// This packs the button into the Window (a container).
// fix.set_height(100);
// fix.set_width(100);
m_fix.set_size_request(1000, 600); //Widget类的成员函数
add(m_fix);
m_fix.show();
m_fix.add(m_button);
// The final step is to display this newly created widget...
m_button.show();
m_btn.set_label("btn_ok");
m_fix.add(m_btn);
m_btn.show();
}
HelloWorld::~HelloWorld()
{
}
bool HelloWorld::on_delete_event(GdkEventAny* event)
{
std::cout << "process quit" << std::endl;
Gtk::Widget::on_delete_event(event);
}
void HelloWorld::on_button_clicked()
{
Gtk::Window window;
// Gtk::Main kit();
Gtk::Main::run(window);
Gtk::Main::quit();
std::cout << "Hello World" << std::endl;
}
/*
* File: main.cpp
* Author: root
*
* Created on 2011年7月28日, 下午7:38
*/
#include "helloworld.h"
#include <gtkmm/main.h>
#include <gtkmm/treeview.h>
#include <gtk-2.0/gtk/gtkwidget.h>
#include <gtkmm/listviewtext.h>
int main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
HelloWorld helloworld;
Gtk::Button button("ok");
Gtk::ListViewText lvt(1);
helloworld.m_fix.add(lvt);
lvt.set_size_request(200, 100);
helloworld.m_fix.move(lvt, 150, 0);
lvt.set_column_title(0, "列表1");
// Glib::ustring ustr("good");
lvt.append_text(Glib::ustring("good"));
// lvt.set_text(1, 1, Glib::ustring("good"));
lvt.show();
Gtk::TreeView tv;
tv.set_size_request(50, 50);
helloworld.m_fix.add(button);
helloworld.m_fix.move(button, 0, 60); //Fixed的成员函数
helloworld.m_fix.add(tv);
helloworld.m_fix.move(tv, 0, 90);
tv.show();
// button.add(helloworld);
button.show();
//Shows the window and returns when it is closed.
Gtk::Main::run(helloworld);
return 0;
}