Re: Adding widget inside a Gtk::Frame





On Mon, 15 Aug 2005, Nickolai Dobrynin wrote:

Marcus,

May I ask you a question back?  Are you using this constructor to create
your desk_widget object:

desk_widget::desk_widget(const std::string& name)
{
 desk_widget::desk_widget();
 set_name(name);
}

If so, I must wonder what you intend this constructor to do.  The first
line creates a default desk_widget object, and, since this object is anonimous,
it goes immediately out of scope.  So, in effect, you create a desk_widget
object inside another desk_widget object.  Is this intentional?

Given this, nothing gets added to your frame in that particular constructor,
so nothing, indeed, should show up except for the frame itself.  Please try
using the first constructor instead and let us know if it works.  That other
constructor looks OK to me, at first glance anyway.

Well, ofcourse your right, works like a charm.

One last thing.  What is the purpose for having show_all() in desk_widget::set_name?
Is it meant to be there?

Mostly to see if this helped, I guess a bit desperate.

To sum things up, this is more of a C++ problem than anything GTK-related.

Actually I did quite much C++ coding a few years back, but since I started my present job, I haven't gotten around to much spare-time coding, so I guess I'm a bit rusty.
Besides Java and XSLT at work, it has mostly been C coding (fvwm).
But this vacation I got the idea to start using GTKmm, thought about it some years ago...

Thanks for your help.

//Marcus

Best,

Nickolai



On Mon, Aug 15, 2005 at 06:49:38PM +0200, Marcus Lundblad wrote:
I have some problem with a widget derived from Gtk::Frame

I have the following (header and source):

------- .hh ----------------------------------------

#include <gtkmm.h>
#include <string>

#ifndef DESK_WIDGET
#define DESK_WIDGET

class desk_widget : public Gtk::Frame {
public:
  desk_widget();
  desk_widget(const std::string& name);

  void set_name(const std::string& name);

private:
  Gtk::VBox desk_box;    // holds label area and graphic area
  Gtk::HBox label_box;   // holds desk indicator and desk label
  Gtk::DrawingArea desk_indicator; //
  Gtk::Label label;  // the desktop name label
  Gtk::Button desk;  // will become a special widget later on...
};

#endif //DESK_WIDGET

--------- .cc -----------------------------------------

#include <iostream>
#include "desk_widget.hh"

desk_widget::desk_widget()
{
  add(desk_box);
  label_box.pack_start(desk_indicator, Gtk::PACK_SHRINK);
  label_box.pack_end(label, Gtk::PACK_SHRINK);
  desk_box.pack_start(label_box, Gtk::PACK_SHRINK);
  desk_box.pack_end(desk, Gtk::PACK_SHRINK);

  label.set_label("Desk");
  desk.set_label("Test");
  show_all();
}

desk_widget::desk_widget(const std::string& name)
{
  desk_widget::desk_widget();
  set_name(name);
}

void
desk_widget::set_name(const std::string& name)
{
  std::cerr << "Setting desk label: " << name << std::endl;
  label.set_label(name);
  show_all();
}

-----------------------------------------------------------------

but only the frame shows up.
Do I need to add the outermost box as a managed widget? Or is something
else dodgy? To me it seems this should work.

Would be thankful if someone has an idea of what's wrong...

//Marcus
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




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