LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2021, 03:39 AM   #1
billc3012
LQ Newbie
 
Registered: Feb 2021
Location: Melbourne, Australia
Distribution: Solus Mate
Posts: 2

Rep: Reputation: Disabled
gtk_grid_attach_next_to issue [solved]


I setup a grid with 4 buttons.
Clicking a button should add a message to the grid below the button.
If I click any button, the window resizes to reflect the size of the message.
However buttons 1-3 show no message.
If I click the 4th button the message is displayed correctly.
If I only have 1 button then everything works correctly.

This is fixed by calling gtk_grid_insert_next_to prior to gtk_grid_attach_next_to

Code:
#include <gtk/gtk.h>
#include <stdbool.h>

#define GWD GtkWidget

typedef struct GWD3{
	GWD *grid;
	GWD *entry;
}GWD3;

GWD *win;


static GWD3 *bldEntry(char *prompt){
	GWD *grid,*lbl,*entry;
	grid=gtk_grid_new();
	lbl=gtk_label_new(prompt);
	entry=gtk_entry_new();
	gtk_entry_set_text(GTK_ENTRY(entry),"1.00 mm");
	gtk_entry_set_alignment(GTK_ENTRY(entry),2);
	gtk_entry_set_max_length(GTK_ENTRY(entry),11);
	gtk_grid_attach(GTK_GRID(grid),lbl,1,0,1,1);
	gtk_grid_attach(GTK_GRID(grid),entry,2,0,1,1);
	GWD3 *ret=g_malloc(sizeof(GWD2));
	ret->grid=grid; ret->entry=entry;
	return ret; }

static gboolean addData(GWD *w, gpointer data){
	GWD *grid=(GWD *)data;
	GWD3 *pair=bldEntry("ENTER Length  ");
	gtk_grid_attach_next_to(GTK_GRID(grid),pair->grid,w,GTK_POS_BOTTOM,2,1);
	gtk_widget_grab_focus(pair->entry);
	gtk_widget_show_all(win);
	return false;}

static GWD *addGrid(){
	GWD *grid=gtk_grid_new();
	GWD *lbl=gtk_label_new("Test Grid");
	gtk_grid_attach(GTK_GRID(grid),lbl,1,0,1,1);
	GWD *btn=gtk_button_new_with_label("Button 2");
	g_signal_connect(btn,"clicked",G_CALLBACK(addData),(gpointer)grid);
	gtk_grid_attach(GTK_GRID(grid),btn,1,1,1,1);
	btn=gtk_button_new_with_label("Button 3");
	g_signal_connect(btn,"clicked",G_CALLBACK(addData),(gpointer)grid);
	gtk_grid_attach(GTK_GRID(grid),btn,1,2,1,1);
	btn=gtk_button_new_with_label("Button 4");
	g_signal_connect(btn,"clicked",G_CALLBACK(addData),(gpointer)grid);
	gtk_grid_attach(GTK_GRID(grid),btn,1,3,1,1);
	btn=gtk_button_new_with_label("Button 5");
	g_signal_connect(btn,"clicked",G_CALLBACK(addData),(gpointer)grid);
	gtk_grid_attach(GTK_GRID(grid),btn,1,4,1,1);
	return grid;}

void btn_clicked(GtkWidget *w, gpointer data){
		g_print("Button clicked\n");}

int main(int argc,char *argv[]){
		gtk_init(&argc,&argv);
		win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
		g_signal_connect(win,"delete_event",gtk_main_quit,NULL);
		GWD *grid=addGrid();
		gtk_container_add(GTK_CONTAINER(win),grid);
		gtk_widget_show_all(win);
		gtk_main();
		return 1;}
Any suggestions welcome.

Thanks in advance
Bill

Last edited by billc3012; 02-15-2021 at 05:23 PM. Reason: Problem solved
 
Old 02-15-2021, 12:34 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Welcome to LQ and the Programming forum!

Your post is not clear to me and you seem to ask no specific question. From your description it seems that everything is working correctly. Could you please edit your post to be specific about the problem you are having, if any, and how the observed behavior differs from what you expect. And please tell us what you have done to try to identify the cause.

You may find it helpful to review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help!
 
Old 02-15-2021, 05:16 PM   #3
billc3012
LQ Newbie
 
Registered: Feb 2021
Location: Melbourne, Australia
Distribution: Solus Mate
Posts: 2

Original Poster
Rep: Reputation: Disabled
It is necessary to call gtk_grid_insert_next_to before calling gtk_grid attach_next_to. If this is not done and the following row has content then gtk documentation says the results are undefined. So gtk works as per documentation.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bind issue? DNS issue? Domain provider issue? Cannot reach Apache virtual hosts internally. rnturn Linux - Networking 5 01-26-2020 10:35 AM
Slack 10.1 -- Mouse issue / X11 issue Pozican Linux - General 4 04-19-2005 03:44 AM
webmin issue, poss security issue bejiita Slackware 3 11-03-2004 06:07 AM
DNS issue or caching issue? AZDAVE Linux - Networking 7 10-02-2004 12:28 AM
Having Issue w/ Truetype fonts - Mozilla Issue clove Linux - Software 4 02-18-2004 08:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration