Gtk4 Gridview Example

I’m new to PyGObject and looking for a complete example using a Gtk4 Gridview loading data from mysql with Python.

The cursor (data) portion of this request is not needed as I’ve done this previously but I’m looking for how to configure columns, headers and set the scrollable area within the grid. The only example I’ve found to date is very basic and doesn’t relate to multiple columns and rows loaded from a mysql database.

Any suggestions greatly appreciated !

Hi,

What sort of data are you going to be showing? If you want a table of text data, you may be better looking at ColumnView rather than GridView.

Hare you looked at and rejected ColumnView?

– Pat

Hi Pat

It would be a datagrid that can hold multiple types of data (images, buttons etc) other than just text.

thanks

OK. I’m still trying to clarify what you’re trying to do so (to the best of my limited ability) I can give an opinion.

The GridView widget will lay out the items in a list in a grid pattern, but doesn’t really assign any meaning to the columns of the grid. Adding a new item anywhere other than the end will move all the other items in the grid, probably to other columns. The columns are simply visual artifacts on the screen - not anything you can address in the data structure.

The ColumnView also deals with a list of objects, but you then control how to put data from those objects into explicit columns. So, if your items came from SQL, you might have each row in the grid represent a row in your query result, and each column in the grid map to a column in query result.

If you determine which of these (or maybe neither?) represents best what you’re trying to do, that will help you choose the appropriate widget. Then we can get into the mechanics of using the widget.

Well…

To be honest I’ve found both Columnview and Gridview very difficult to use and understand.

What I ended up doing and it couldn’t of been easier was add a Scrolled Window widget with it’s child being a Grid and loaded data directly from my cursor into that Grid.

Now all I need is to create a few custom objects showing images in one case and text in the other and hook up click events.

Done

Appreciate the input…

1 Like