[gtkmm] Widget size bug?



Greetings Everyone,

I'd like to know if there is a bug in getting the size of a widget using
get_height() or I'm using the function wrong.  It seems to me that if a
widget is modified after the initial constuction, the size variables
don't get updated.  I haven't looked very deep into the problem to see
at what point things might be incorrect, but I'd be willing to look into
it if someone confirms.  The sample code below should give a good
indication of my problem.  The heights of all the widgets are the same
even after the label is changed from 1 to 3 lines and a large border is
added around the button.

Concerning the border: is the border suppose to count as part of the
widgets width and height?  I think it should, but it doesn't appear to.

Cheers,
Ryan
------

#include <gtkmm/main.h>
#include <gtkmm/box.h>
#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <iostream>

class MainWindowClass
  : public Gtk::Window
{
public:
    MainWindowClass();
};

MainWindowClass::MainWindowClass()
{
    using namespace std;
    using namespace Gtk;
        
    Gtk::HBox * hbox1 = new Gtk::HBox(false, 0);
    Gtk::Label * label1 = new Gtk::Label("label1");
    Gtk::VBox * vbox1 = new Gtk::VBox(false, 0);
    Gtk::Button * button1 = new Gtk::Button("button1");
    Gtk::Label * label2 = new Gtk::Label("label2");
    
    vbox1->pack_start(*button1, Gtk::PACK_SHRINK, 0);
    vbox1->pack_start(*label2, Gtk::PACK_SHRINK, 0);
    hbox1->pack_start(*label1, Gtk::PACK_SHRINK, 0);
    hbox1->pack_start(*vbox1, Gtk::PACK_SHRINK, 0);
    
    this->add(*hbox1);
    this->show_all();
    
    cout << "label1 height: " << label1->get_height() << endl;
    cout << "hbox1 height: " << hbox1->get_height() << endl;
    cout << "button1 height: " << button1->get_height() << endl;
    cout << "label2 height: " << label2->get_height() << endl;
    
    button1->set_border_width(10);
    label2->set_text("this is\nnow a\n3 line label");
    
    cout << "\nafter changes\n";
    cout << "label1 height: " << label1->get_height() << endl;
    cout << "hbox1 height: " << hbox1->get_height() << endl;
    cout << "button1 height: " << button1->get_height() << endl;
    cout << "label2 height: " << label2->get_height() << endl;
}

int main(gint argc, gchar **argv)
{
    Gtk::Main kit(argc, argv);
    MainWindowClass main_window;
   
    Gtk::Main::run(main_window);
    return 0;
}

----
~~~~~~~~~~~~~~~~~~~~



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