[pygtk] TreeView/CellRenderText and numbers

2 views
Skip to first unread message

Olaf Devik

unread,
Oct 12, 2011, 5:29:59 AM10/12/11
to py...@daa.com.au
I am struggling with TreeView and CellRendererText.

I have a ListStore containing a number of fields with strings and
integers. The ListStore is connected to a TreeView and the string fields
render well as expected, but the fields with integers will not render.

How can I render integer values in the TreeView?

Probably a simple question with a simple answer, but I have so far not
found any simple solution. Most problems listed in the FAQs are far to
advanced compared to my simple problem.

Tips are welcome

Regards

Olaf Devik


_______________________________________________
pygtk mailing list py...@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Saeed Rasooli

unread,
Oct 12, 2011, 5:51:12 AM10/12/11
to olaf....@mollefaret.no, py...@daa.com.au
Please put your code.
You should define the right type in ListStore (int/str), and if the int feild is editable, I think you have to handle "edited" signal manually to validate input text.

Dieter Verfaillie

unread,
Oct 12, 2011, 6:09:05 AM10/12/11
to olaf....@mollefaret.no, py...@daa.com.au
On Wed, 12 Oct 2011 11:29:59 +0200, Olaf Devik wrote:
> I am struggling with TreeView and CellRendererText.
>
> I have a ListStore containing a number of fields with strings and
> integers. The ListStore is connected to a TreeView and the string
> fields render well as expected, but the fields with integers will not
> render.
>
> How can I render integer values in the TreeView?

Exactly like you would render a string value from your model. For
example, assuming field 1 in your model is of type int:

cell = gtk.CellRendererText()
intcolumn = gtk.TreeViewColumn('Amount')
intcolumn.pack_start(cell, True)
intcolumn.add_attribute(cell, 'text', 1)

A complete and working example is attached.

mvg,
Dieter

treeview_columns.py

Olaf Devik

unread,
Oct 12, 2011, 7:21:25 AM10/12/11
to py...@daa.com.au
Thanks to both replies. Info from Dieter did the trick, the critical
line was intcolumn.add_attribute(cell,'text',1).

I tried to set same trough use of
gtk.TreeView.insert_column_with_attributes, which was ok for the columns
with string, but failed when an integer was required. When that failed,
my confusion went to a high level.

So basically, I am now one step closer to master the mysteries of
TreeView and ListStore.

Regards

Olaf Devik

Dieter Verfaillie

unread,
Oct 13, 2011, 1:58:12 PM10/13/11
to olaf....@mollefaret.no, py...@daa.com.au
On 12/10/2011 13:21, Olaf Devik wrote:
> Thanks to both replies. Info from Dieter did the trick, the critical
> line was intcolumn.add_attribute(cell,'text',1).
>
> I tried to set same trough use of
> gtk.TreeView.insert_column_with_attributes, which was ok for the columns
> with string, but failed when an integer was required. When that failed,
> my confusion went to a high level.

Ah yes, insert_column_with_attributes also works (and even
saves a bit of typing). See attachment :)

mvg,
Dieter

treeview_columns.py
Reply all
Reply to author
Forward
0 new messages