[gtkmm] Gtk::DrawingArea help required
- From: ej <e j virgin net>
- To: gtkmm-list gnome org
- Subject: [gtkmm] Gtk::DrawingArea help required
- Date: Wed, 22 Sep 2004 22:01:18 +0100
Dear all,
I have only just started learning to use gtkmm and I'm having problems
with Gtk::DrawingArea.
The only example I can find that works is the radar example. This
subclassess Gtk::DrawingArea.
I want to use GTK::DrawingArea directly without having to subclass it. I
wrote a very basic app,
based on the radar example and the hello world example (see below).
The idea is that the pressing the button will generate data for some
random lines to be stored in
the main app object (picture). Then the expose event on the drawing area
will take this data and
draw lines with it.
The button signal handler works fine when I comment out the expose event
handler connect line, but
with that line the program fails to compile with the following :
ejames sonata:/data/My_NEAT/StockDB/helloworld> g++ -o picture main.cpp
Picture.cpp `pkg-config gtkmm-2.0 --cflags --libs`
Picture.cpp: In constructor `Picture::Picture()':
Picture.cpp:24: error: no matching function for call to `
Glib::SignalProxy1<bool, GdkEventExpose*>::connect(SigC::Slot0<void>)'
/opt/gnome/include/gtkmm-2.0/glibmm/signalproxy.h:136: error: candidates
are:
SigC::Connection Glib::SignalProxy1<R, P1>::connect(const SigC::Slot1<R,
P1>&, bool) [with R = bool, P1 = GdkEventExpose*]
How can I get signal handlers for the drawing area to connect properly ?
The reason I'm not sublcassing the DrawingArea (like the radar app) is
because I will eventually have widgets which update
the data which will be stored in Picture, subclassing will mean I won't
be able to access the data in Picture from within
the sublcasses DrawingArea.
Any help with this would be most appreciated.
Regards,
EJ
**********
main.cpp :
**********
#include <gtkmm/main.h>
#include "Picture.h"
int main (int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
Picture picture;
Gtk::Main::run(picture);
return 0;
}
*********
Picture.h
*********
#ifndef PICTURE_H
#define PICTURE_H
#include <gtkmm/drawingarea.h>
#include <gdkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/box.h>
#include <gtkmm/window.h>
#include <gtkmm/main.h>
class Picture : public Gtk::Window {
public:
Picture();
virtual ~Picture();
protected:
//Signal handlers:
virtual void on_button_clicked();
virtual void on_expose_event();
//Member widgets:
Gtk::HBox box;
Gtk::Button button;
Gtk::DrawingArea draw_area;
};
#endif // PICTURE_H
***********
Picture.cpp
***********
#include <gtkmm/drawingarea.h>
#include <gdkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/box.h>
#include <gtkmm/window.h>
#include <gtkmm/main.h>
#include <iostream>
#include "Picture.h"
Picture::Picture() : box(false,0), button("Button") {
// pack the drawing area into the box
box.pack_start(draw_area,Gtk::PACK_EXPAND_WIDGET,0);
// pack the button into the box
box.pack_start(button,Gtk::PACK_SHRINK,0);
// signal handler for button
button.signal_clicked().connect(SigC::slot(*this,
&Picture::on_button_clicked));
// signal handler for draw_area
draw_area.signal_expose_event().connect(SigC::slot(*this,
&Picture::on_expose_event));
// set initial size of drawing area to 500x500
draw_area.set_size_request(500,500);
// add the box to the window and show all the widgets
add(box);
show_all();
// The final step is to display this newly created widget...
button.show();
}
Picture::~Picture() {
}
void Picture::on_button_clicked() {
std::cout << "button clicked" << std::endl;
}
void Picture::on_expose_event() {
std::cout << "expose event generated" << std::endl;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]