|
|
| Author |
Message |
|
|
rotalever Familiar Face
Joined: 24 Feb 2007 Posts: 11
|
Posted: Sun Feb 25, 2007 11:10 am Post subject: hscale |
|
|
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? |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 376 Location: State College, Pennsylvania
|
Posted: Sun Feb 25, 2007 5:40 pm Post subject: |
|
|
| 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(). |
|
| Back to top |
|
 |
rotalever Familiar Face
Joined: 24 Feb 2007 Posts: 11
|
Posted: Sun Feb 25, 2007 6:25 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 376 Location: State College, Pennsylvania
|
Posted: Sun Feb 25, 2007 6:40 pm Post subject: |
|
|
| You could use GtkRange's change-value signal to clamp the position of the scale. |
|
| Back to top |
|
 |
rotalever Familiar Face
Joined: 24 Feb 2007 Posts: 11
|
Posted: Sun Feb 25, 2007 6:48 pm Post subject: |
|
|
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... :? |
|
| Back to top |
|
 |
rotalever Familiar Face
Joined: 24 Feb 2007 Posts: 11
|
Posted: Sun Feb 25, 2007 8:25 pm Post subject: |
|
|
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.... |
|
| Back to top |
|
 |
|