GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Nov 23, 2014 5:53 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: hscale
PostPosted: Sun Feb 25, 2007 11:10 am 
Offline
Familiar Face

Joined: Sat Feb 24, 2007 11:40 am
Posts: 9
Hi,
In my program I included a hscale with the code gtk_hscale_new({adjustment});. The adjustment ist set to gtk_adjustment_new(1,0,3,1,1,0);. As you can guess, the hscale should let the user choose between 4 (0-3) different values. My problem is, that the user can also drag the slider between two values. For example it becomes "2.4335". How can I force the widget/user that the slider snaps always only to the 4 possible integer values?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 5:40 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
You have to set the "digits" property of GtkScale. By setting it to 0, no decimal places will be available. You could also create the GtkHScale with gtk_hscale_new_with_range().

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 6:25 pm 
Offline
Familiar Face

Joined: Sat Feb 24, 2007 11:40 am
Posts: 9
The Good thing: It works with setting digits to 0 -> the slider snaps to the nearest value.
The Bad thing: It works only if the app is displaying the value with setting gtk_scale_set_draw_value () to TRUE...
Is there a way to get the effect without displaying the value?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 6:40 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
You could use GtkRange's change-value signal to clamp the position of the scale.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 6:48 pm 
Offline
Familiar Face

Joined: Sat Feb 24, 2007 11:40 am
Posts: 9
Yeah I tried that before, with a seperate callback function which does this snaps. It works good, but you see those flickerings:
For example the user puts the slider at 1.3 with the mouse -> GTK draws it first at 1.3 -> the change-value signal calls my callback function (g_signal_connect(..)) -> my callback function snaps the value to the nearest Integer -> value = 1.0 -> GTK draws it at 1.0
As you can see, there are two drawing calls, which will cause a flickering.

I will use this, if there is no other choice, but I am hoping for another method... :?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 8:25 pm 
Offline
Familiar Face

Joined: Sat Feb 24, 2007 11:40 am
Posts: 9
Ooops, I misunderstood your suggestion :oops:
I did it with "value-changed" not "change-value" before... That's totaly different. Now it works! :D
Thank you....


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 1 guest


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