0
votes

I'm working on a X-plotter like widget that plots incomming data live. I already searched for an solution to realize a scrolling along the x-axis if the widget has to much values and so they don't fit.

I had the folling approaches to realize it:

  • derive from a widget that supports scrolling and child widgets and add my own widget while making it bigger and bigger during the live updates: -> Which parent do I need to use and how do I avoid to draw all the stuff that is currently not visible?
  • modify my widget in a way that it supports the scrollbars itself -> but how?
  • draw/handle my own scrollbars -> worstcase :(

I really searched the web for suggestions or examples, but there is nothing about how to "construct" custom controls in a good way (beyond drawing something) esp. in the case of interaction... Sorry but I'm a newbie at GTK in general :/

1
Can you add some code or a link to what you're currently trying? There isn't enough context to tell what you're asking here.Christian Ternus
@ChristianTernus Well whole code is bit to much, but I will try to add the important stuff: * ownwidget is based on gtk.Drawingarea) * placed in a VBOX on the app window * uses ATM only do_expose trigger to draw, no sizing requests etc. * internally using CAIRO to plotMaM
Why can't you use a canvas library that gives you all of that already? Such as GooCanvas or, for more complex stuff, Clutter?gianmt
Thanks, I will check this out. I wasn't aware at the start of my widget, that this part will become that tricky ;)MaM
@gianmt So GooCanvas is for C++ and Clutter uses OpenGL. But I try to create an Python app (sry, add it to title), with minimal dependencies.MaM

1 Answers

2
votes

Most widgets in Gtk do not have scrollbars.

If you want to scroll the entire widget, you have to implement the GtkScrollable interface. Then, you add the widget to a GtkScrolledWindow. The scrolled window has the scrollbars, those GtkScrollbars are linked with GtkAdjustments which are passed to your custom widget through the GtkScrollable interface set_vadjustment and set_hadjustment.

If you just want to add a scrollbar and control its behaviour yourself, then you need to somehow add a GtkScrollbar in your widget, which means you will need to make it a container too.

The GtkScrollable approach is the following, first you implement vadjustment and hadjustment setters and getters, then when the GtkAdjustments are set, you set its lower and upper limits and the page size(how much of the widget is visible at once). After that, you connect their value-changed signal so you can refresh your widget when the scrollbars are dragged. A GtkScrollable doesn't get to check the scrollbars, only the adjustments that will be bound to the scrollbars. When drawing the widget you get the adjustments' value property in order to determine how much the scrollbars have shifted in the horizontal and vertical axes.