1. EuGTK:Column Widths in GtkTreeView

Irv,

Is there a way to conform the column widths to a percentage of the available space?

For example, with three columns, I'd like their initial widths to be something like {80%,10%,10%}.

As it is now, the first column contents are making the first column push everything else off the side (and unseen).

Any ideas?

new topic     » topic index » view message » categorize

2. Re: EuGTK:Column Widths in GtkTreeView

euphoric said...

Irv,

Is there a way to conform the column widths to a percentage of the available space?

For example, with three columns, I'd like their initial widths to be something like {80%,10%,10%}.

As it is now, the first column contents are making the first column push everything else off the side (and unseen).

Any ideas?

Sure, but if the text in the first column is too long, it will have to be ellipsized so it can fit into a reduced width.

There are "min width", "max width", and "fixed width" properties for the columns. The widths are in pixels, you could compute this by taking 80% of the main window width, or just choose a number that looks good.

Columns will have to be named e.g. create(GtkColumn,"name=col1,...") so that you can retrieve its renderer. Ellipsize modes are 0 = none, 1 = start, 2 = middle, 3 = end. Mode 2 works best here, I think.

set("col1->renderer","ellipsize",2) -- obtain and set column's renderer  
set(col1,"min width",300) -- set desired width in pixels 
set(col1,"resizable",TRUE) -- allow sliding the columns to reveal more of the text  

If other columns contain data that doesn't fit, you may have to repeat the code above for those, too. Otherwise, they'll probably fit automatically.

new topic     » goto parent     » topic index » view message » categorize

3. Re: EuGTK:Column Widths in GtkTreeView

irv said...

There are "min width", "max width", and "fixed width" properties for the columns. The widths are in pixels, you could compute this by taking 80% of the main window width, or just choose a number that looks good.

OK, dang it. I tried "min width" as "min_width," due to the GTK docs showing that property. Should I assume all properties in EuGTK are without dashes/symbols? Where do you document the use of these properties for EuGTK? I need to read some docs! smile

ADDED: "min-width" works during both create() and set()

I think it will be enough to get the GtkTreeView width in order to set the initial column widths, right? We shall see!

irv said...

Columns will have to be named e.g. create(GtkColumn,"name=col1,...") so that you can retrieve its renderer. Ellipsize modes are 0 = none, 1 = start, 2 = middle, 3 = end. Mode 2 works best here, I think.

set("col1->renderer","ellipsize",2) -- obtain and set column's renderer  
set(col1,"min width",300) -- set desired width in pixels 
set(col1,"resizable",TRUE) -- allow sliding the columns to reveal more of the text  

If other columns contain data that doesn't fit, you may have to repeat the code above for those, too. Otherwise, they'll probably fit automatically.

OK, cool. Thank you!

new topic     » goto parent     » topic index » view message » categorize

4. Re: EuGTK:Column Widths in GtkTreeView

euphoric said...

OK, dang it. I tried "min width" as "min_width," due to the GTK docs showing that property. Should I assume all properties in EuGTK are without dashes/symbols? Where do you document the use of these properties for EuGTK? I need to read some docs!

Properties can use dashes or spaces. You chose the one which won't work, underline!

Documentation for the signals can be found by going the GTK doc page for the widget in question, say, GtkTreeView, and clicking on the signals tab at top of page. Same for the properties. Bear in mind that many or most of the properties are inherited. Follow the links upward in the Object Hierarchy, if you don't see what you're looking for.

Or easier, include the line:

    set(win,"interactive debugging",1)  

just before the call to main(). Learn your way around the debugger.

Now, if you try to code ? get(tv,"width"), and run in a terminal, you'll see an error message:

ERROR: 
****** Invalid call: GtkTreeView->get_width  
because treeviews have no width. The window which contains the treeview does, however. Here's what works:

 ? get(get(tv,"window"),"width") -- crazy, eh? 

BTW, you have to dig really deep into the GTK docs to find that out. Or search online.

Now, if you're ellipsizing the long category name, but need to be able to see it in full, you have several choices - drag the columns to make room, or better, set a tooltip that will contain the full, un-ellipsed text, or put a status bar somewhere containing the full text. Second and third options require a small function to update as the mouse moves.

new topic     » goto parent     » topic index » view message » categorize

5. Re: EuGTK:Column Widths in GtkTreeView

RESOLVED: Looks like I can grab the "allocation" property of the GtkTreeView!

irv said...

Now, if you try to code ? get(tv,"width"), and run in a terminal, you'll see an error message:

ERROR: 
****** Invalid call: GtkTreeView->get_width  

Yep! I seen't it!

irv said...

because treeviews have no width. The window which contains the treeview does, however. Here's what works:

 ? get(get(tv,"window"),"width") -- crazy, eh? 

Well, the width of the "window" doesn't help, as that isn't the size of the TreeView. I want only the width of the container of the widget (I guess).

So, I have a GtkTreeView inside a GtkScrolledWindow inside a GtkBox inside a GtkPaned... and none of those have width, so I can't get the width of the GtkTreeView!

That's messed up.

How would I keep my columns relatively-spaced and remain completely inside the GtkScrolledWindow?!

Or maybe I've done something wrong.

Thank you for the guidance!

new topic     » goto parent     » topic index » view message » categorize

6. Re: EuGTK:Column Widths in GtkTreeView

? get(get(scrl,"window"),"width") -- or whatever you named the scrolled window; 

That works fine for me. But get_allocation returns {x,y,w,h}, so it may be more useful.

This of course must be gotten whenever the window size is changed by the user, and a new width must be figured and set.

And you never set a min or max or fixed size on ALL columns, always leave at least the last to figure out what's left.

https://sites.google.com/site/euphoriagtk/Screenshot%20from%202019-08-30%2017-59-51.png?attredirects=0&d=1

Above, status bar and ellipsis.

new topic     » goto parent     » topic index » view message » categorize

7. Re: EuGTK:Column Widths in GtkTreeView

irv said...

That works fine for me.

That doesn't duplicate my use case exactly. My GtkTreeView is inside a GtkPaned and is the second child. When it starts to get narrow, the final columns are fading out of view.

No worries, though!

I've got it working almost perfectly using the "allocated" property of the GtkTreeView! (This does provide the width of the control, from what I can tell!)

Also, since I'm only setting the widths at the app start-up, further adjustments are not necessary. I just want it nice when it opens. smile

I have another question coming up about sorting columns... smile

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu