GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri May 24, 2013 12:55 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Wich widget is the right one for small output.
PostPosted: Mon Aug 10, 2009 5:57 am 
Offline
Familiar Face

Joined: Mon Aug 10, 2009 4:28 am
Posts: 17
Location: Bremen, Germany
Hi folks,

I'm doing a small visualization program and reading values from an RS232. Now I want to show them.

First a thought, GtkLabel is the right for just showing 4 digits. But then I saw, it is not possible to change forground and background color.

Then I tried GtkEntry, just for output, but then I saw, if it is not editable, you always get sound if you click on it.

Then I tried GtkText with GtkBuffer, but this is a very big and powerful widget. How can I use this for just a 4 digit output?

This is my first Gtk program, befor I used always ncurses. But this time I also need x,y chart, that's way I need graphics. So I thougt, Gtk would be a good solution :-)

I hope, someone can show me a way, thanks,

Michael ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 10, 2009 7:51 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums.

If you intend to show only limited amount of text, then GtkLabel is the best option here. And as for the text and background color, you can change them in more than one way. One way is to set properties using gtk_widget_modify_bg and gtk_widget_modify_text. Second way would be to use gtk_label_set_markup function, which takes PangoMarkup as a parameter. PangoMarkup is a HTML-ish markup language, which can, among other things, set background and foreground colors of the text. For more info about Pango Markup Language, have a look here.

Tadej


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 10, 2009 8:17 am 
Offline
Familiar Face

Joined: Mon Aug 10, 2009 4:28 am
Posts: 17
Location: Bremen, Germany
Hello Tadej,

thanks a lot for your answer :-) Beginning is always a hard way.

I found the gtk_widget_modify_bg already days ago, but there is written, that it is not working with GtkLabel. I need therefor a parent widget.

So, do I understand this in the right way? I've to build an GtkEventBox. There I bring with gtk_event_box_set_above_child my GtkLabel in?

And than I can use modify_bg?

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 10, 2009 9:26 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.
Captain_Stone wrote:
I found the gtk_widget_modify_bg already days ago, but there is written, that it is not working with GtkLabel. I need therefor a parent widget.

So, do I understand this in the right way? I've to build an GtkEventBox. There I bring with gtk_event_box_set_above_child my GtkLabel in?

And than I can use modify_bg?
Almost exactly as you said. The only thing that you don't have to do is to set event box above your child (this is done when you want to catch events, for background changing, you can leave it alone).

Tadej


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 10, 2009 9:33 am 
Offline
Familiar Face

Joined: Mon Aug 10, 2009 4:28 am
Posts: 17
Location: Bremen, Germany
Hi Tadej,

thanks! I'll try this later at home and tell you about my experience.

Michael ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 11, 2009 4:24 am 
Offline
Familiar Face

Joined: Mon Aug 10, 2009 4:28 am
Posts: 17
Location: Bremen, Germany
Hi Tadej,

I did it like spoken with GtkEventBox, but then I had a problem with changing the color.

I do not unerstand the 3. Parameter from gtk_widget_modify_bg wich represent the color (I know the structure but found no example to use it in a GTK program. Do you have a link?

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 11, 2009 7:06 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

I don't have any sample links, but using GdkColor from withing GTK+ application is usually done like this:
Code:
{
   GdkColor color;

#if 1
   /* Define green color */
   color.red   = 0;
   color.green = 65535;
   color.blue  = 0;
#else
   /* This is exactly the same as above */
   gdk_color_parse( "green", &color );
#endif

   gtk_widget_modify_bg( widget, GTK_STATE_NORMAL, &color );
}

Hopefully, this will help a bit.

Tadej


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 11, 2009 4:30 pm 
Offline
Familiar Face

Joined: Mon Aug 10, 2009 4:28 am
Posts: 17
Location: Bremen, Germany
Hi my helpful Tadej :-)

tadeboro wrote:
gtk_widget_modify_bg( widget, GTK_STATE_NORMAL, &color );


Oh - damned - I always was writing "color" not "&color" :-(
(And the Error message was just "wrong type of parameter")

Now, it's working, I changed the color - thanks so much. Now I will see, how far I can go without a help...

Michael ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group