Re: Widget movement signal in custom widget

Why don't you use a Gtk::Layout instead of a DrawingArea, then you can add the progressbar as a child widget and show it on button press and hide it on button release.


----- Original Message ----- From: "Matt Strange" <mstrange wans net>
To: <gtkmm-list gnome org>
Sent: Thursday, July 07, 2005 9:31 AM
Subject: Widget movement signal in custom widget

Hello All,
       I am trying to creating a custom widget which has a
Gtk::Progressbar floating above it in a popup Window.  The
Progressbar's window only appears when the mouse button is down (it's
hidden the rest of the time).  To keep the floating Progressbar in
correct position relative to the widget, I need to have the
Progressbar's popup window move whenever the custom widget is moved.
However, I cannot find the right signal for the "widget moved" event.
The generally recommended "configure_event" signal is only called on
resizing signals, even with all GdkEventFlags on.
       Assuming there is no better way to link this floating
Progressbar to the custom widget (e.g. a method which makes moving
Progressbar unnecessary), I would appreciate any help adding a method
to the CustomDrawingArea (see code below) which is called when the
widget is moved (`on_configure_event' attempts to do that in the
example code).
       The following code is modified from one of the Tutorial
Examples and is simply an overridden DrawingArea with the additional
Progressbar.  Note that `on_configure_event' is only called when the
widget is resized; `on_configure_event' is not called when the widget
is moved.

Thank you very much for your time,
Matt Strange

#include <iostream>
#include <gtkmm/main.h>
#include <gtkmm/drawingarea.h>
#include <gtkmm/window.h>
#include <gtkmm/progressbar.h>

class CustomDrawingArea : public Gtk::DrawingArea
 CustomDrawingArea(int x_size = 0, int y_size = 0);
 virtual bool on_expose_event(GdkEventExpose* event);
 virtual bool on_configure_event(GdkEventConfigure* event);
 virtual bool on_button_press_event(GdkEventButton* event);
 virtual bool on_button_release_event(GdkEventButton* event);
 int m_width, m_height;
 Gtk::ProgressBar* _progressbar;
 Gtk::Window* _progressbar_window;

CustomDrawingArea::CustomDrawingArea(int x_size, int y_size)
 : DrawingArea(), m_width(x_size), m_height(y_size)
 set_size_request(m_width, m_height);
 // note: STRUCTURE_MASK should make the configure events
 // recievable...

 // make the progressbar & a popup window that it sits in
 _progressbar_window = new Gtk::Window(Gtk::WINDOW_POPUP);
 _progressbar = manage(new Gtk::ProgressBar);
 delete _progressbar_window;

bool CustomDrawingArea::on_expose_event(GdkEventExpose*)
 Glib::RefPtr<Gdk::Window> win = get_window();
 Glib::RefPtr<Gdk::GC> some_gc = Gdk::GC::create(win);

 Gdk::Color some_color("white");
 Glib::RefPtr<Gdk::Colormap> some_colormap =

 //Draw circle
 win->draw_arc(some_gc, true, 0, 0, 50, 50, 0, 23040);

 return true;

CustomDrawingArea::on_configure_event(GdkEventConfigure* event)
 std::cerr << "on_configure_event called\n";
 // ERROR: this is only called when the window is resized, how to
 // call when moved?
 int x,y;
 return true;

CustomDrawingArea::on_button_press_event(GdkEventButton* event)
 return true;

CustomDrawingArea::on_button_release_event(GdkEventButton* event)
 return true;

main(int argc, char* argv[])
 Gtk::Main gtk_main(argc, argv);

 Gtk::Window window;
 CustomDrawingArea my_widget(200,200);



 return 0;

gtkmm-list mailing list
gtkmm-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]