How do you rotate a gtk widget?
Let's say the widget in question is a VBox con开发者_JAVA技巧taining a Label and two Buttons.
Furthermore, let's say the degree of rotation desired is 90°.
How does one go about rotating it? I do not think this is possible by default but I do think it is possible.
However, I have no idea how to get started. Do I write a custom widget? What do I subclass?
You can fake it like this:
label.set_angle(90)
button1.get_child().set_angle(90) # assuming it's not a stock button
button2.get_child().set_angle(90)
vbox.set_orientation(gtk.ORIENTATION_HORIZONTAL)
Firstly, if your widget does not have its own X window (VBox doesn't), put it inside EventBox.
Secondly, assuming that you've got X composite extension enabled in your X server, you will be able to do that by manually tweaking your widget's X window using Xlib or an equivalent one. Warning, this is a hacky solution and will not work if your user does not have compositing extensions enabled.
I don't see any way to do this without compositing extensions... well, other than drawing everything by hand. GTK uses Cairo graphics library to draw widgets, and theoretically it would be enough to set transformation matrix inside Cairo... but I see no practical possibility of doing that.
I know it's been a while since this question was answered, but if you want to get started with subclassing, here's the C code to do it. This is taken from the GTK-Demo suite.
https://github.com/GNOME/gtk/blob/gtk-3-22/demos/gtk-demo/offscreen_window.c
精彩评论