Friday, 2 April 2021

GTK - Python Treeview Column Reorder Warnings

I have a simple GTK GUI with a treeview on it. It gives the following errors when I drag columns to reorder. How this problem could be fixed?

Warnings:

Gtk-WARNING **: 15:43:03.151: Negative content width -8 (allocation 1, extents 5x4) while allocating gadget (node button, owner GtkButton)

Gtk-WARNING **: 15:43:03.151: Negative content height -1 (allocation 1, extents 1x1) while allocating gadget (node button, owner GtkButton)

Gtk-WARNING **: 15:43:05.886: Negative content width -8 (allocation 1, extents 5x4) while allocating gadget (node button, owner GtkButton)

Simplified Code:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib

builder = Gtk.Builder()
builder.add_from_file('test.glade')
window1 = builder.get_object('window1')
treeview1 = builder.get_object('treeview1')

class Signals:
    def on_window1_destroy(self, widget):
        Gtk.main_quit()

list_data = [["text1", "data1", "data2"], ["text2", "data1", "data2"], ["text3", "data1", "data3"]]

treestore1 = Gtk.TreeStore(str, str, str)
piter1 = treestore1.append(None, list_data[0])
piter2 = treestore1.append(piter1, list_data[1])
piter3 = treestore1.append(piter1, list_data[2])

treeview1.set_model(treestore1)

for i, column_title in enumerate(["col1", "col2", "col3"]):
    renderer = Gtk.CellRendererText()
    column = Gtk.TreeViewColumn(column_title, renderer, text=i)
    treeview1.append_column(column)
    column.set_sort_column_id(i)
    column.set_resizable(True)
    column.set_reorderable(True)

treeview1.expand_all()

builder.connect_signals(Signals())
window1.show_all()
Gtk.main()

Software versions: GTK 3, Python 3.8.

Important:

  • Glade GUI file will be given if needed.
  • I had similar warnings for a listview in my previous attempts.


from GTK - Python Treeview Column Reorder Warnings

No comments:

Post a Comment