Skip to content
Advertisement

GTK – Python Treeview Sort Column Data (File Size – Byte Data)

I have a GTK GUI with Python code. There is a treeview on the GUI. I need to list file sizes on the treeview and sort them by file size by clicking on the column. But it sorts files by using their sizes as string.

What is the common way for sorting this files?

  1. Using string file size values (with a cell function or custom sort function).
  2. Using integer file size values (with a cell function or custom sort function).
  3. Another way?

Here is the simplified code:

JavaScript

Here is the Glade file:

JavaScript

Software information: Python 3.7, GTK3.

Advertisement

Answer

You need to have a hidden column in the store with the file size as an integer that is used solely for sorting. Here’s an example:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement