ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is it possible to position controls, such as LABELS, EDITBOX, COMBOBOX, CHECKBOXES, BUTTONS manually?
Or must we use gtk_box_new() and gtk_box_pack_start()
Example:
This code just creates a window with a button on it.
The button is not visible because something is wrong.
I have similar code done in Qt.
Qt has functions to establish a parent------child relationship.
So, I can create a window
create a button
make the button a child of the window,
then I can change the position and size of the button and the coordinate is with respect to the {0,0} of the client area of the window.
Qt has some box and autopositioning functions. But it feels like I don’t have control and besides, sometimes, I want to do something custom.
Code:
static void OnActivate(GtkApplication *app)
{
//Create a new window
GtkWidget *pTheWindow=gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(pTheWindow), "www.lucidarme.me");
gtk_window_resize((GtkWindow *)pTheWindow, 500, 700);
//Create a new button
GtkWidget *button=gtk_button_new_with_label("Hello, World!");
//When the button is clicked, close the window passed as an argument
g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_window_close), pTheWindow);
//gtk_window_set_child(GTK_WINDOW(window), button);
gtk_window_set_attached_to(GTK_WINDOW(button), pTheWindow);
gtk_window_present(GTK_WINDOW(pTheWindow));
gtk_window_move(GTK_WINDOW(pTheWindow), 10, 10);
gtk_window_move(GTK_WINDOW(button), 10, 10);
gtk_window_resize(GTK_WINDOW(button), 100, 22);
//gtk_window_set_default_geometry(GtkWindow *window, gint width, gint height);
//gtk_window_move(GtkWindow *window, gint x, gint y);
//gtk_window_resize((GtkWindow *)pTheLabel, 100, 22);
}
int main(int argc, char *argv[])
{
//Create a new application
GtkApplication *app;
int status;
app=gtk_application_new("com.example.GtkApplication", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(OnActivate), NULL);
status=g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.