3

Using Python and Gtk3, I have created a Gtk.TreeView and put it inside a Gtk.ScrolledWindow. I don't like horizontal scroll bars, so I removed it using the Gtk.PolicyType.NEVER, but now I can't resize the window in that direction.

So the question is: how can I get ride of the horizontal scroll bar and at the same time to be able to resize the window horizontally?

Any help is appreciated!

Obs: this is how I created the ScrolledWindow:

    self.scrolledwindow = Gtk.ScrolledWindow()
    self.scrolledwindow.set_policy(Gtk.PolicyType.NEVER,
                                   Gtk.PolicyType.AUTOMATIC)
    self.add(self.scrolledwindow)
skytux
  • 1,236
  • 2
  • 16
  • 19
  • Show some code. It sounds as if you didn't set the policy of the scrolledwindow, or something. – unwind Mar 25 '13 at 14:57
  • As I said in my question, I used `Gtk.PolicyType.NEVER` for the horizontal scroll bar. – skytux Mar 25 '13 at 15:03
  • 1
    Do you mean that the window can't be re-sized horizontally *at all*, or that it can't (for instance) be more narrow than some width that might be the GtkTreeView's preferred width? – unwind Mar 25 '13 at 15:09
  • It can't be more narrow than some width. Actually, the ScrolledWindow always has the width of the wider row in the GtkTreeView. Sorry if I described my problem in a wrong way and many thanks @unwind for your help. – skytux Mar 25 '13 at 15:16
  • I finally figured it out. I assigned a fixed size to the `Gtk.CellRendererText` using `renderer_text.set_fized_size(200, -1)`. In this way I have a column whose minimum size is 200, and it is not limited anymore by the width of the wider row. – skytux Mar 26 '13 at 17:16
  • 1
    It is recommended you write your solution as answer and accept it. In that way, other users will know this question has a valid answer. – gpoo Apr 12 '13 at 02:24

1 Answers1

4

SOLUTION:

The problem was that the window couldn't be more narrow than the wider row in the Gtk.TreeView, and I also wanted my window without horizontal scroll bars. The final code that solves my problem is this:

self.scrolledwindow = Gtk.ScrolledWindow()
self.scrolledwindow.set_policy(Gtk.PolicyType.NEVER,
                               Gtk.PolicyType.AUTOMATIC)

...

renderer_text = Gtk.CellRendererText(weight=600)
renderer_text.set_fixed_size(200, -1)
column_text = Gtk.TreeViewColumn('Name', renderer_text, text=1)

In that way, the Gtk.CellRendererText has a minimum size and can be re-sized once the window is opened.

skytux
  • 1,236
  • 2
  • 16
  • 19