Question

I have a gtkscrolledwindow and there is a gtk image in it. How can i get current showing area in GtkScrolledWindow? For example my image is 1366x768 pix and 300x400 pix part of image is showing in scrolledwindow. I want to get coordinates of showing part like (x,y,width,height) I'm looking here: https://developer.gnome.org/gtkmm/unstable/classGtk_1_1ScrolledWindow.html but can't find any solution. Thanks.

EDIT:The solution from user1146332 Thank you very much. For the python codes:

    x = self.scrolledwindow.get_hadjustment()
    print str(x.get_page_size()) + " width of showing area"  
    y =self.scrolledwindow.get_vadjustment()
    print str(y.get_page_size()) + " height of showing area"
    print str(x.get_upper()) + " image width in scrolledwindow"
    print str(y.get_upper()) + " image height in scrolledwindow"
    print str(x.get_value()) + " x position"
    print str(y.get_value()) + " y position"

Note that for adjustments which are used in a GtkScrollbar, the effective range of allowed values goes from adjustment->lower to adjustment->upper - adjustment->page_size.

Was it helpful?

Solution

I guess you want to achieve something like this:

coordinates

Whereas x and y describes the point located at the upper left corner of the image section and width and height are related to the size of the image section. Further i assume that the GtkImage object is added to a GtkViewport widget and the GtkViewport is added to a GtkScrolledWindow.

Unfortunately i can't give you a python specific answer since i don't know anything about it. But if you are able to transfer information from gtk's reference manual to python you should be able to implement it.

If you want information about the coordinates of the image section you first have to get the vadjustment and hadjustment properties of the GtkScrolledWindow widget. These properties are GtkAdjustment objects and contains the information you need. The page-size property of those objects is related to the size of the visible image section i.e width and height. Whereas the value property of both vadjustment and hadjustment defines the point at the upper left corner of the image section i.e. x and y.

If you want to react upon changes of the mentioned properties asynchronously you should connect the changed and value-changed signals of both adjustment objects to one and the same signal handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top