开发者

gtkmm button not maintaining size and location

I have created two gtkmm button and added to HBox object. I called pack_end, and maintained the size as 21,20. But, the sizes are not maintained. Here is the code i have written and the window that i got while running the program.

gtkmm button not maintaining size and location

Note: MYWindow is subclass of Gtk::Window

void MYWindow::customizeTitleBar() { //create a vertical box Gtk::VBox *vBox = new Gtk::VBox(FALSE,0);

//create a horizontal box
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0);
hBox->set_border_width(5);

//create title bar image
Gtk::Image *titleBarImage = new Gtk::Image("src/WindowTitleBar.png");
titleBarImage->set_alignment(Gtk::ALIGN_LEFT);

// hBox->pack_start(*titleBarImage,Gtk::PACK_EXPAND_WIDGET,0);

//create cloze button for window
mButtonClose = new Gtk::Button;
(*mButtonClose).set_size_request(21,20);
Gtk::Image *mImage =  new Gtk::Image("src/Maximize.jpeg");
(*mButtonClose).add(*mImage);
(*mButtonClose).set_image_position(Gtk::POS_TOP);

// connecting close window function when cliked on close button 
//(*mButtonClose).signal_clicked().connect( sigc::mem_fun(this, &MYWindow::closeWindow));

hBox->pack_end(*mButtonClose,Gtk::PACK_EXPAND_WIDGET,0);
Gtk::Button * mBtton = new Gtk::Button;
mBtton->set_size_request(21,20);
Gtk::Image *img =  new Gtk::Image("src/Maximize.jpeg");
mBtton->add(*img);
mBtton->set_image_position(Gtk::POS_TOP);

hBox->pack_end(*mBtton,Gtk::PACK_EXPAND_WIDGET,0);

vBox->add(*hBox);

//drawing area box
Gtk::HBox *hBoxDrawingArea = new Gtk::HBox;

Gtk::DrawingArea *mDraw开发者_JS百科ingArea = new Gtk::DrawingArea;

hBoxDrawingArea->pack_start(*mDrawingArea,Gtk::PACK_EXPAND_WIDGET,0);

vBox->add(*hBoxDrawingArea);

//status bar hBox
Gtk::HBox *hBoxStatusBar = new Gtk::HBox;

vBox->add(*hBoxStatusBar);

this->add(*vBox);

this->show_all();

}


I am not yet a gtk expert (but I'm learning), here's one thing you can try, which is what I've been doing. Make a little standalone project using glade. Glade makes it really easy to screw around with all the packing settings so you can immediately see the effects of your changes. I think in the case of resizing the window, you'll have to save the glade file and run your program (using gtkbuilder to render the glade file) and manually resize the window to see the effect, but once you make the standalone project, you can use it for other gtk testing. And if you're like me, you'll get swayed by the wonderfulness that is glade and build your whole system that way.

But basically, it sounds like a packing issue, because I've got buttons that don't resize all over the place. As for not moving, I'm not sure you can do that, but again I'm not an expert. I think you should be able to pin the size of some if not all of the hbox pieces so that the button inside them will not move, but I'm not sure what happens if you don't have any hbox parts that can't be variably sized to take up the slack when you grow the window.

Again, sounds like something fun to try in glade. :-)


I think you pack to FALSE , Maybe this is the problem :

Gtk::HBox *hBox = new Gtk::HBox(TRUE,0)

I use python gtk with something like this:

box1.pack_start(box2,False)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜