0

I am attempting to fix the size of a widget in GTK+, specifically using Gtk2hs with Haskell.

I have drawn an image in a DrawingArea and I would like to specify the exact size of this drawing area. I do not want other widgets or the user to make this widget larger or smaller. Is this possible?

Note, I am using ghc version 6.10.4 under Ubuntu 9.10. Gtk2hs version 0.10.1.

2 Answers 2

3

You can call gtk_widget_set_size_request() to cause a widget to request a fixed height and width. You'll have to determine the Haskell equivalent.

Note that this is generally a Bad Idea(TM) and you should arrange your containers and child packing properties such that your controls are sized appropriately. For example, changing the size of your image will require code changes if you're hardcoding size request values.

1
  • Thanks. This was halfway to fixing my problem. I also needed to place it inside a Fixed pane (as opposed to HBox or VBox, say) to prevent the enclosing widget from resizing the DrawingArea.
    – Necrototem
    Feb 16, 2010 at 23:41
2

The Gtk2Hs function to fix a widget size is :

widgetSetSizeRequest 
  :: WidgetClass self    
  => self    
  -> Int    
  -> Int    
  -> IO ()

with as arguments :

  1. The widget
  2. Width of the Widget
  3. Height of the Widget

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.