|
|
用Glade设计界面并生成代码,用Anjuta编辑。就需要自己加两行button的click代码就行了,第二个俺不会,请帮忙看看。我用的Gtkmm.
window1_glade.hh
- // generated 2006/8/6 17:22:39 CST by bruce@Blueberry.(none)
- // using glademm V2.0.0.1
- //
- // DO NOT EDIT THIS FILE ! It was created using
- // glade-- /home/bruce/Projects/FirstApp/FirstApp.glade
- // for gtk 2.6.4 and gtkmm 2.2.12
- //
- // Please modify the corresponding derived classes in ./src/window1.hh and./src/window1.cc
- #ifndef _WINDOW1_GLADE_HH
- # define _WINDOW1_GLADE_HH
- #if !defined(GLADEMM_DATA)
- #define GLADEMM_DATA
- #include <gtkmm/accelgroup.h>
- class GlademmData
- {
-
- Glib::RefPtr<Gtk::AccelGroup> accgrp;
- public:
-
- GlademmData(Glib::RefPtr<Gtk::AccelGroup> ag) : accgrp(ag)
- {
- }
-
- Glib::RefPtr<Gtk::AccelGroup> getAccelGroup()
- { return accgrp;
- }
- };
- #endif //GLADEMM_DATA
- #include <gtkmm/window.h>
- class window1_glade : public Gtk::Window
- {
- protected:
- GlademmData *gmm_data;
- protected:
-
- window1_glade();
-
- ~window1_glade();
- private:
- virtual void on_button1_clicked() = 0;
- virtual void on_button2_clicked() = 0;
- };
- #endif
复制代码
window1_glade.cc
- // generated 2006/8/6 17:22:39 CST by bruce@Blueberry.(none)
- // using glademm V2.0.0.1
- //
- // DO NOT EDIT THIS FILE ! It was created using
- // glade-- /home/bruce/Projects/FirstApp/FirstApp.glade
- // for gtk 2.6.4 and gtkmm 2.2.12
- //
- // Please modify the corresponding derived classes in ./src/window1.cc
- #if defined __GNUC__ && __GNUC__ < 3
- #error This program will crash if compiled with g++ 2.x
- // see the dynamic_cast bug in the gtkmm FAQ
- #endif //
- #include "config.h"
- #include "window1_glade.hh"
- #include <gdk/gdkkeysyms.h>
- #include <gtkmm/accelgroup.h>
- #include <gtkmm/label.h>
- #include <gtkmm/entry.h>
- #include <gtkmm/box.h>
- #include <gtkmm/image.h>
- #include <gtkmm/alignment.h>
- #include <gtkmm/button.h>
- window1_glade::window1_glade(
- ) : Gtk::Window(Gtk::WINDOW_TOPLEVEL)
- {
-
- Gtk::Window *window1 = this;
- gmm_data = new GlademmData(get_accel_group());
-
- Gtk::Label *inputLabel = Gtk::manage(new class Gtk::Label("这里的文字将随着输入变化"));
- Gtk::Label *leftLabel = Gtk::manage(new class Gtk::Label("输入:"));
- Gtk::Entry *inputEntry = Gtk::manage(new class Gtk::Entry());
- Gtk::HBox *hbox1 = Gtk::manage(new class Gtk::HBox(false, 0));
- Gtk::Image *image1 = Gtk::manage(new class Gtk::Image(Gtk::StockID("gtk-apply"), Gtk::IconSize(4)));
- Gtk::Label *label3 = Gtk::manage(new class Gtk::Label("确认"));
- Gtk::HBox *hbox3 = Gtk::manage(new class Gtk::HBox(false, 2));
- Gtk::Alignment *alignment1 = Gtk::manage(new class Gtk::Alignment(0.5, 0.5, 0, 0));
- Gtk::Button *button1 = Gtk::manage(new class Gtk::Button());
- Gtk::Image *image2 = Gtk::manage(new class Gtk::Image(Gtk::StockID("gtk-quit"), Gtk::IconSize(4)));
- Gtk::Label *label4 = Gtk::manage(new class Gtk::Label("退出"));
- Gtk::HBox *hbox4 = Gtk::manage(new class Gtk::HBox(false, 2));
- Gtk::Alignment *alignment2 = Gtk::manage(new class Gtk::Alignment(0.5, 0.5, 0, 0));
- Gtk::Button *button2 = Gtk::manage(new class Gtk::Button());
- Gtk::HBox *hbox2 = Gtk::manage(new class Gtk::HBox(false, 0));
- Gtk::VBox *vbox1 = Gtk::manage(new class Gtk::VBox(false, 0));
- inputLabel->set_alignment(0.5,0.5);
- inputLabel->set_padding(0,0);
- inputLabel->set_justify(Gtk::JUSTIFY_CENTER);
- inputLabel->set_line_wrap(false);
- inputLabel->set_use_markup(false);
- inputLabel->set_selectable(false);
- leftLabel->set_alignment(0.5,0.5);
- leftLabel->set_padding(0,0);
- leftLabel->set_justify(Gtk::JUSTIFY_LEFT);
- leftLabel->set_line_wrap(false);
- leftLabel->set_use_markup(false);
- leftLabel->set_selectable(false);
- inputEntry->set_flags(Gtk::CAN_FOCUS);
- inputEntry->set_visibility(true);
- inputEntry->set_editable(true);
- inputEntry->set_max_length(0);
- inputEntry->set_text("");
- inputEntry->set_has_frame(true);
- inputEntry->set_activates_default(false);
- hbox1->pack_start(*leftLabel, Gtk::PACK_SHRINK, 2);
- hbox1->pack_start(*inputEntry, Gtk::PACK_EXPAND_WIDGET, 2);
- image1->set_alignment(0.5,0.5);
- image1->set_padding(0,0);
- label3->set_alignment(0.5,0.5);
- label3->set_padding(0,0);
- label3->set_justify(Gtk::JUSTIFY_LEFT);
- label3->set_line_wrap(false);
- label3->set_use_markup(false);
- label3->set_selectable(false);
- hbox3->pack_start(*image1, Gtk::PACK_SHRINK, 0);
- hbox3->pack_start(*label3, Gtk::PACK_SHRINK, 0);
- alignment1->add(*hbox3);
- button1->set_flags(Gtk::CAN_FOCUS);
- button1->set_border_width(2);
- button1->set_relief(Gtk::RELIEF_NORMAL);
- button1->add(*alignment1);
- image2->set_alignment(0.5,0.5);
- image2->set_padding(0,0);
- label4->set_alignment(0.5,0.5);
- label4->set_padding(0,0);
- label4->set_justify(Gtk::JUSTIFY_LEFT);
- label4->set_line_wrap(false);
- label4->set_use_markup(false);
- label4->set_selectable(false);
- hbox4->pack_start(*image2, Gtk::PACK_SHRINK, 0);
- hbox4->pack_start(*label4, Gtk::PACK_SHRINK, 0);
- alignment2->add(*hbox4);
- button2->set_flags(Gtk::CAN_FOCUS);
- button2->set_border_width(2);
- button2->set_relief(Gtk::RELIEF_NORMAL);
- button2->add(*alignment2);
- hbox2->pack_start(*button1, Gtk::PACK_SHRINK, 40);
- hbox2->pack_start(*button2, Gtk::PACK_SHRINK, 40);
- vbox1->pack_start(*inputLabel, Gtk::PACK_SHRINK, 4);
- vbox1->pack_start(*hbox1, Gtk::PACK_EXPAND_WIDGET, 2);
- vbox1->pack_start(*hbox2, Gtk::PACK_EXPAND_WIDGET, 2);
- window1->set_border_width(2);
- window1->set_title("我的第一个Gnome程序");
- window1->set_default_size(500,400);
- window1->set_modal(false);
- window1->property_window_position().set_value(Gtk::WIN_POS_NONE);
- window1->set_resizable(false);
- window1->property_destroy_with_parent().set_value(false);
- window1->add(*vbox1);
- inputLabel->show();
- leftLabel->show();
- inputEntry->show();
- hbox1->show();
- image1->show();
- label3->show();
- hbox3->show();
- alignment1->show();
- button1->show();
- image2->show();
- label4->show();
- hbox4->show();
- alignment2->show();
- button2->show();
- hbox2->show();
- vbox1->show();
- window1->show();
- button1->signal_clicked().connect(SigC::slot(*this, &window1_glade::on_button1_clicked));
- button2->signal_clicked().connect(SigC::slot(*this, &window1_glade::on_button2_clicked));
- }
- window1_glade::~window1_glade()
- { delete gmm_data;
- }
复制代码
window1.h
- // generated 2006/8/6 17:13:28 CST by bruce@Blueberry.(none)
- // using glademm V2.0.0.1
- //
- // newer (non customized) versions of this file go to window1.hh_new
- // you might replace
- // class foo : public foo_glade { ... };
- // by
- // typedef foo_glade foo;
- // if you didn't make any modifications to the widget
- #ifndef _WINDOW1_HH
- # include "window1_glade.hh"
- # define _WINDOW1_HH
- class window1 : public window1_glade
- {
- protected:
- virtual void on_button1_clicked();
- virtual void on_button2_clicked();
- };
- #endif
复制代码
window1.cc
- // generated 2006/8/6 17:13:28 CST by bruce@Blueberry.(none)
- // using glademm V2.0.0.1
- //
- // newer (non customized) versions of this file go to window1.cc_new
- // This file is for your program, I won't touch it again!
- #include "config.h"
- #include "window1.hh"
- #include <gtkmm/main.h>
- #include <gtkmm/label.h>
- #include <gtkmm/entry.h>
- void window1::on_button1_clicked()
- {
- ?????
- }
- void window1::on_button2_clicked()
- {
- Gtk::Main::quit();
- }
复制代码
================
我想点一下确认按钮,在顶上的label上显示entry里的文字。那个gmm_data是个什么东东,就那里搞不明白,而且是private的。
初学,迫切的想写出第一个程序来,有些文档什么的来不及看,请勿见怪,谢谢![/img] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|