Reputation: 21
Please, i need the function that can set the location of a Widget on gtk+ using pixels ! and an example of it.
Thank you!
Upvotes: 1
Views: 3801
Reputation: 21
You can use the GtkFixed container:
The GtkFixed widget is a container which can place child widgets at fixed positions and with fixed sizes, given in pixels.
And since you didn't mention a language, here is an example in Python:
from gi.repository import Gtk
import sys
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.Window.__init__(self, title="GtkFixed", application=app)
# Set the window size
self.set_size_request(200, 200)
# Add GtkFixed to the main window
container = Gtk.Fixed()
self.add(container)
button = Gtk.Button("Test Button")
# Add the button in the (x=20,y=100) position
container.put(button, 20, 100)
class Application(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self)
def do_activate(self):
self.mainWindow = MainWindow(self)
self.mainWindow.show_all()
def do_startup(self):
Gtk.Application.do_startup(self)
application = Application()
exitStatus = application.run(sys.argv)
sys.exit(exitStatus)
(unfortunately i can't post the result image)
Upvotes: 2