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 

gtkbutton putting image

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


Joined: 11 Mar 2010
Posts: 21

PostPosted: Fri Mar 12, 2010 4:42 pm    Post subject: gtkbutton putting image Reply with quote

Hi Experts,

I am trying to load image in the gtkbutton widget. I am using gtk_button_set_image(*,*) function for this. But this sets the image to be displayed normally. When button gets focus by mouse or when clicked it shows same image with original button borders. I want to display three images basically. One for displaying normally, one for pressed and one for on focus by mouse / keyboard.

Please help.

Kind Regards
-Durgesh O' Mishra
Back to top
Joel
GTK+ Guru


Joined: 06 Apr 2008
Posts: 225
Location: Fortress of solitude

PostPosted: Fri Mar 12, 2010 6:18 pm    Post subject: Reply with quote

See the signals:

* clicked
* enter

A good example:
Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#include <gtk/gtk.h>

enum MOTION
{
     NONE, HOVER, CLICKED, PRESSED, RELEASED
};

void button_motion (GtkButton *button, int m)
{
     GtkWidget *img;
     switch (m)
     {
          case RELEASED:
         
case HOVER:
         
{
               img = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,GTK_ICON_SIZE_LARGE_TOOLBAR);
               break;
          }
          case CLICKED:
         
{
               img = gtk_image_new_from_stock(GTK_STOCK_OPEN,GTK_ICON_SIZE_LARGE_TOOLBAR);
               break;
          }
          case NONE:
         
{
               img = gtk_image_new_from_stock(GTK_STOCK_OK,GTK_ICON_SIZE_LARGE_TOOLBAR);
               break;
          }
          case PRESSED:
         
{
               img = gtk_image_new_from_stock(GTK_STOCK_DIALOG_INFO,GTK_ICON_SIZE_LARGE_TOOLBAR);
               break;
          }
          default:
          {
               img = gtk_image_new_from_stock(GTK_STOCK_OK,GTK_ICON_SIZE_LARGE_TOOLBAR);
               break;
          }
     }
     gtk_button_set_image(button,img);
}

int main(int argc, char *argv[])
{
     GtkWidget *win;
     GtkWidget *button;
     gtk_init(&argc,&argv);
     win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER);
     g_signal_connect(G_OBJECT(win),"destroy",G_CALLBACK(gtk_main_quit),NULL);
     button = gtk_button_new();
     /* signals */
     
g_signal_connect(G_OBJECT(button),"show",G_CALLBACK(button_motion),(gpointer)NONE);
     g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(button_motion),(gpointer)CLICKED);
     g_signal_connect(G_OBJECT(button),"enter",G_CALLBACK(button_motion),(gpointer)HOVER);
     g_signal_connect(G_OBJECT(button),"pressed",G_CALLBACK(button_motion),(gpointer)PRESSED);
     g_signal_connect(G_OBJECT(button),"released",G_CALLBACK(button_motion),(gpointer)RELEASED);
     g_signal_connect(G_OBJECT(button),"leave",G_CALLBACK(button_motion),(gpointer)NONE);

     gtk_container_border_width(GTK_CONTAINER(win), 25);
     gtk_container_add(GTK_CONTAINER(win),button);
     gtk_widget_show_all(win);
     gtk_main();
    return 0;
}
Back to top
durgesh.mishra
Familiar Face


Joined: 11 Mar 2010
Posts: 21

PostPosted: Mon Mar 15, 2010 8:51 am    Post subject: partly successful Reply with quote

Hi Joel,

Thanks for this piece of code.

Basically, when "enter" event happens, I automatically see the button boundaries, I want to avoid that also..

Kind Regards
-Durgesh O Mishra
Back to top
zerohour



Joined: 17 May 2010
Posts: 1

PostPosted: Mon May 17, 2010 12:31 am    Post subject: Reply with quote

Joel thanks for the code. How could I use custom images on the buttons instead of stock?
I saw some thread showing code for this but I've searched and searched and can't find it again.
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