SpinButton

A SpinButton allows the user to select a value from a range of numeric values. It has an Entry widget with increment and decrement buttons at the side. Clicking the buttons causes the value to 'spin' up and down across the range of possible values. The Entry widget may also be used to enter a value directly.

Värdet kan ha ett justerbart antal decimaler, och stegstorleken kan konfigureras. SpinButton har även en funktion för ”automatisk upprepning”: att hålla ner öknings- eller minskningsknappen kan valfritt få värdet att ändras snabbare ju längre knappen hålls ner.

SpinButtons use an Adjustment object to hold information about the range of values. These Adjustment attributes are used by the Spin Button like so:

  • value: value for the Spin Button

  • lower: lower range value

  • upper: upper range value

  • step_increment: value to increment/decrement when pressing mouse button 1

  • page_increment: value to increment/decrement when pressing mouse button 2

  • page_size: unused

Vidare kan musknapp 3 användas för att hoppa direkt till värdena upper eller lower.

SpinButton kan skapa en standard-Adjustment som du kan komma åt genom get_adjustment()-metoden, eller så kan du ange en befintlig Adjustment i konstruktorn.

Metoder

Antalet decimaltecken kan ändras med metoden set_digits().

Du kan ställa in stegningsrutans värde med metoden set_value(), och erhålla det med get_value().

The spin() method 'spins' the SpinButton, as if its increment or decrement button had been clicked. You need to specify a Gtk::SpinType to specify the direction or new position.

För att hindra användaren från att mata in icke-numeriska tecken i inmatningsfältet skickar du true till metoden set_numeric().

To make the SpinButton 'wrap' between its upper and lower bounds, use the set_wrap() method.

To force it to snap to the nearest step_increment, use set_snap_to_ticks().

Referens

Exempel

Här är ett exempel på användning av en SpinButton:

SpinButton

Källkod