0

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 :/

8
  • 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. Commented Oct 16, 2013 at 18:42
  • @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 plot Commented Oct 16, 2013 at 18:47
  • Why can't you use a canvas library that gives you all of that already? Such as GooCanvas or, for more complex stuff, Clutter? Commented Oct 16, 2013 at 19:42
  • Thanks, I will check this out. I wasn't aware at the start of my widget, that this part will become that tricky ;) Commented Oct 16, 2013 at 20:25
  • @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. Commented Oct 16, 2013 at 21:19

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, in the End I used GTKScrolledWindow and add all my stuff inside. Here it is a gtk.fixed Layout as I like to calculate my virtual position manually. So if the widgets get moved outside the current view, scrollbars appear. Briliant :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.