OKButtonとbackButtonは縦に並べて表示されます。OKButtonが上に、下に配置されています。私はそれらを左に同じ列に戻し、右にOKしたい。 現在、私は5タブのタブウィンドウを持っています。各タブには、リストストアのツリービューがあります。 liststoreの登録項目をクリックすると、新しいスクロールウインドウが作成されます。このスクロールウインドウには、戻るボタンとokボタンがある別のリストがあります。背中クリックすると、前のメニューに戻り、空のコールバックfunction.Iはあなたの提案に感謝していOK火災行ctivated信号 GtkBox
ためOKボタンと戻るボタンは縦に1つずつ表示され、他は下に横並びに配置する必要があります。
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
GtkWidget *scrolledwindow;
struct param
{
GtkWidget* backbutton;
GtkWidget* Okbutton;
GtkWidget* scrolledwindow;
GtkWidget*newChild;
GtkWidget*oldChild;
};
GtkWidget * init_tree();
GtkWidget * init_tree2();
static void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
static void Back (GtkButton *button, gpointer user_data)
{
struct param* parameters = (struct param*)user_data;
gtk_widget_hide(GTK_WIDGET(parameters->scrolledwindow));
gtk_container_remove(GTK_CONTAINER(parameters->scrolledwindow), GTK_WIDGET(parameters->newChild));
gtk_container_add(GTK_CONTAINER(parameters->scrolledwindow), parameters->oldChild);
gtk_widget_hide (GTK_WIDGET(parameters->backbutton));
gtk_widget_show_all (GTK_WIDGET(parameters->scrolledwindow));
}
static void Ok (GtkButton *button, gpointer user_data)
{
}
static void replace_tab(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data)
{
struct param* parameters = (struct param*)user_data;
gchar *string;
GtkTreeIter iter;
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_model_get (model, &iter, 0, &string, -1);
g_print ("activated: %s\n", string);
if(!strcmp(string,"Register"))
{
GtkWidget* liststore = GTK_WIDGET(gtk_tree_view_get_model(tree_view));
gtk_widget_hide(GTK_WIDGET(parameters->scrolledwindow));
gtk_container_remove(GTK_CONTAINER(parameters->scrolledwindow), GTK_WIDGET(tree_view));
gtk_container_add(GTK_CONTAINER(parameters->scrolledwindow), parameters->newChild);
gtk_widget_show (GTK_WIDGET(parameters->backbutton));
gtk_widget_show (GTK_WIDGET(parameters->Okbutton));
gtk_widget_show_all (GTK_WIDGET(parameters->scrolledwindow));
}
else if(!strcmp(string,"New Configuration"))
{
}
else if(!strcmp(string,"Edit Configuration"))
{
}
else if(!strcmp(string,"Delete Configuration"))
{
}
else if(!strcmp(string,"Add location to turn-off place list"))
{
}
else if(!strcmp(string,"Disable Turn-off Places"))
{
}
else if(!strcmp(string,"Disable Distance"))
{
}
else if(!strcmp(string,"Enable Distance"))
{
}
else if(!strcmp(string,"Factory Reset"))
{
}
}
GtkWidget * init_tree()
{
GtkListStore *liststore = gtk_list_store_new(1, G_TYPE_STRING);
GtkTreeIter treeiter;
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Register", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "New Configuration", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Edit Configuration", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Delete Configuration", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Add location to turn-off place list", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Disable Turn-off Places", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Enable Turn-off Places", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Disable Distance", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Enable Distance", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Factory Reset", -1);
gtk_list_store_append(liststore, &treeiter);
GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore));
GtkCellRenderer *cellrenderertext = gtk_cell_renderer_text_new();
GtkTreeViewColumn *treeviewcolumn = gtk_tree_view_column_new_with_attributes("Settings",
cellrenderertext,
"text", 0,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn);
return treeview;
}
GtkWidget * init_tree2()
{
GtkListStore *liststore = gtk_list_store_new(1, G_TYPE_STRING);
GtkTreeIter treeiter;
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "a", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "b", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "c", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "d", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "e", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "f", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Aptosid", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "OpenSuSE", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Linux Mint", -1);
gtk_list_store_append(liststore, &treeiter);
gtk_list_store_set(liststore, &treeiter, 0, "Arch Linux", -1);
GtkWidget *treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore));
GtkCellRenderer *cellrenderertext = gtk_cell_renderer_text_new();
GtkTreeViewColumn *treeviewcolumn = gtk_tree_view_column_new_with_attributes("Distributions",
cellrenderertext,
"text", 0,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), treeviewcolumn);
return treeview;
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
GtkWidget *notebook = gtk_notebook_new();
gtk_container_add(GTK_CONTAINER(window), notebook);
int count;
gchar *text;
for (count = 1; count <= 5; count++)
{
text = g_strdup_printf("Page %d", count);
GtkWidget *label = gtk_label_new(text);
GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
GtkWidget *backbutton = gtk_button_new_with_label ("Back");
gtk_widget_set_no_show_all (backbutton, TRUE);
GtkWidget *Okbutton = gtk_button_new_with_label ("Ok");
gtk_widget_set_no_show_all (Okbutton, TRUE);
gtk_box_pack_start (GTK_BOX(vbox), scrolledwindow, TRUE, TRUE, 0);
gtk_box_pack_end (GTK_BOX(vbox), backbutton, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX(vbox), Okbutton, FALSE, FALSE, 0);
GtkWidget* treeview = init_tree();
GtkWidget* treeview2 = init_tree2();
struct param* parameters = malloc(sizeof(struct param));
parameters->backbutton = backbutton;
parameters->Okbutton = Okbutton;
parameters->scrolledwindow = scrolledwindow;
parameters->oldChild= treeview;
parameters->newChild= treeview2;
g_signal_connect(treeview, "row-activated", G_CALLBACK(replace_tab), (gpointer) parameters);
g_signal_connect(backbutton, "clicked", G_CALLBACK(Back), (gpointer) parameters);
g_signal_connect(Okbutton, "clicked", G_CALLBACK(Ok), (gpointer) parameters);
gtk_container_add(GTK_CONTAINER(scrolledwindow), treeview);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, label);
}
gtk_widget_show_all(window);
gtk_main();
return 0;
}
@Sagar、GtkGridの「添付」の長さと幅はピクセル単位ではないことに注意してください。 –