Note that there are some explanatory texts on larger screens.

plurals
  1. POCenter fixed-size GtkDrawingArea widget inside of parent widget
    primarykey
    data
    text
    <p>I've got a glade layout going, and in it I have a fixed-size GtkDrawingArea. The current relevant part of the hierarchy is:</p> <pre><code>GtkWindow &gt; GtkVBox &gt; GtkHPaned &gt; GtkViewport &gt; GtkAlignment &gt; GtkFixed &gt; GtkDrawingArea </code></pre> <p>Currently, the GtkFixed widget draws at the top-left corner of the GtkViewport.</p> <p>However, I'd really like it if the GtkFixed (and thus its only child, the GtkDrawingArea) were centered within GtkViewport (except, of course, when the widget is compressed to the point where it doesn't fit its contents and the scrollbars appear).</p> <p>What's the best way to accomplish this? (I'm using pygtk to do actual application logic, but this should be a general gtk question)</p> <p>Here is a representative code sample:</p> <pre><code>import gtk class Controller: def on_window1_destroy(self, widget, data=None): gtk.main_quit() def __init__(self): self.builder = gtk.Builder() self.builder.add_from_file("sample.glade") self.window = self.builder.get_object("window1") self.builder.connect_signals(self) def on_drawingarea1_expose_event(self, widget, event): cr = widget.window.cairo_create() cr.set_source_rgb(0,0,0) cr.paint() return True if __name__ == "__main__": client = Controller() client.window.show() gtk.main() </code></pre> <p>And a sample glade file with the same issue:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;interface&gt; &lt;requires lib="gtk+" version="2.16"/&gt; &lt;!-- interface-naming-policy project-wide --&gt; &lt;object class="GtkWindow" id="window1"&gt; &lt;signal name="destroy" handler="on_window1_destroy"/&gt; &lt;child&gt; &lt;object class="GtkVBox" id="vbox1"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;child&gt; &lt;object class="GtkHPaned" id="hpaned1"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;property name="can_focus"&gt;True&lt;/property&gt; &lt;child&gt; &lt;object class="GtkLabel" id="label1"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;property name="label" translatable="yes"&gt;label&lt;/property&gt; &lt;/object&gt; &lt;packing&gt; &lt;property name="resize"&gt;False&lt;/property&gt; &lt;property name="shrink"&gt;True&lt;/property&gt; &lt;/packing&gt; &lt;/child&gt; &lt;child&gt; &lt;object class="GtkScrolledWindow" id="scrolledwindow1"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;property name="can_focus"&gt;True&lt;/property&gt; &lt;property name="hscrollbar_policy"&gt;automatic&lt;/property&gt; &lt;property name="vscrollbar_policy"&gt;automatic&lt;/property&gt; &lt;child&gt; &lt;object class="GtkAlignment" id="alignment1"&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;child&gt; &lt;object class="GtkFixed" id="fixed1"&gt; &lt;property name="width_request"&gt;300&lt;/property&gt; &lt;property name="height_request"&gt;300&lt;/property&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;child&gt; &lt;object class="GtkDrawingArea" id="drawingarea1"&gt; &lt;property name="width_request"&gt;300&lt;/property&gt; &lt;property name="height_request"&gt;300&lt;/property&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;signal name="expose_event" handler="on_drawingarea1_expose_event"/&gt; &lt;/object&gt; &lt;/child&gt; &lt;/object&gt; &lt;/child&gt; &lt;/object&gt; &lt;/child&gt; &lt;/object&gt; &lt;packing&gt; &lt;property name="resize"&gt;True&lt;/property&gt; &lt;property name="shrink"&gt;True&lt;/property&gt; &lt;/packing&gt; &lt;/child&gt; &lt;/object&gt; &lt;packing&gt; &lt;property name="position"&gt;0&lt;/property&gt; &lt;/packing&gt; &lt;/child&gt; &lt;/object&gt; &lt;/child&gt; &lt;/object&gt; &lt;/interface&gt; </code></pre> <p>And lastly... a sample image of the issue... <a href="https://imgur.com/eyTvO.png" rel="nofollow noreferrer"><img src="https://imgur.com/eyTvO.png" alt="Screeshot @ imgur"></a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload