GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Displaying an image in GtkImage widget

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
flyjason
Familiar Face


Joined: 04 Mar 2007
Posts: 19

PostPosted: Sun Mar 04, 2007 9:12 pm    Post subject: Displaying an image in GtkImage widget Reply with quote

Hi all,

I'm a novice in gtk+ programming; I should actually use it for doing a project. My project is based on ARToolKit which is a library for building Augmented Reality (AR) applications. In short, AR is the superimposition of virtual imagery on the real world. More information on ARToolKit can be found @ www.hitl.washington.edu/artoolkit/. So, I have to use GTK+ as interface tool and obviously integrate the interface with ARToolKit....something really unclear to me up till now :shock:. I'll be glad if somebody could comment on this as well.

Something I want to do is to display an image in a GtkImage widget after choosing which image to display via a combo box. For testing purposes, I've used a button (i.e. click on the button & display the image).

I'm trying the following code (on the button - onclick event), but it doesn't work :( :

Code: (Plaintext)
1
2
3
GtkWidget *img_objectdesign;
img_objectdesign = gtk_image_new_from_file ("filename.jpg");
gtk_widget_show(img_objectdesign);


I use Glade to design the interface and I work on Windows.

Actually I obtained the following code on the web, so I modified it as above because on the interface window I put a GtkImage widget named as "img_objectdesign":

Code: (Plaintext)
1
2
3
GtkWidget *image;
image = gtk_image_new_from_file ("filename.jpg");
gtk_widget_show(image);


I don't know if I'm doing the right thing or if something is missing, but one thing is for sure is that nothing's happening!! I click on the button and no image is displayed. :(

Can't understand something: I used Glade to make the interface, hence it generated some code automatically (creates callbacks.c, interface.c, etc). In Glade you can name your widgets. My question is that can you access a widget directly in your gtk+ code??

I mean can I put something like

Code: (Plaintext)
1
img_objectdesign = gtk_image_new_from_file ("filename.jpg");


directly (on a button event)?? ...and bearing to the fact that I named the GtkImage widget as "img_objectdesign" in Glade. But in doing so, I obtain compilation errors!! :(

So how do I use the widgets (name) directly in the gtk+ code??

I know I'm asking a lot of questions, but I hope you understand that I'm a beginner and many things are unclear to me unfortunately. :(
I don't even know if I'm formulating my questions well or if the questions are really questions? :?

Furthermore I'm really behind schedule in my project. Please help! :idea:
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 427
Location: Portland, OR USA

PostPosted: Tue Mar 06, 2007 9:09 pm    Post subject: Reply with quote

Quote:
I don't know if I'm doing the right thing or if something is missing, but one thing is for sure is that nothing's happening!! I click on the button and no image is displayed.


Your code to create an image is alright, but it wasn't added to any container. So it doesn't exist anywhere visually. And, since your image is defined in the glade file, you don't want to create a *new* GtkImage but instead set the image of that existing reference to a GtkImage.

Quote:
Can't understand something: I used Glade to make the interface, hence it generated some code automatically (creates callbacks.c, interface.c, etc). In Glade you can name your widgets. My question is that can you access a widget directly in your gtk+ code??


I see by your more recent post, that you have partially figured this out. However, I must point out that the code generation with Glade is deprecated and in Glade3, libglade is the supported method. Something you might want to read up on.

Personally, I'm using Linux and thus cannot be much help for things specific to Windows, but will try to help you as much as possible. If you'd like to post/send your complete little test application, I'll take a look and fix it for you.
Back to top
flyjason
Familiar Face


Joined: 04 Mar 2007
Posts: 19

PostPosted: Tue Mar 06, 2007 11:31 pm    Post subject: Reply with quote

Thank you for your help.

I'll post my application as it progresses.

In fact, the problem was how to reference widgets. I had a look at interface.c and saw the following line:
Code: (Plaintext)
1
/* Store pointers to all widgets, for use by lookup_widget(). */


So I pointed out that the lookup_widget() function was the key to access widgets.

So can I conclude that every widget is accessible via lookup_widget()??

I've used it but I don't really understand the parameter passing :(. I don't think I've mastered it and it would be nice if you could explain it to me and perhaps the concept of container as well. I feel it's important because of course I've got to have control over all the widgets.
:)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP