Sample Code 523: How to extend GtkSpinButton? |
|
Written by kksou
|
|
Wednesday, 08 October 2008 |
|
Problem This is in response to Peter's post titled "extending GtkSpinButton".
He would like to extend the GtkSpinButton class as shown below:

Solution
Sample Code 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
| <?php $window = new GtkWindow(); $window->set_title($argv[0]); $window->set_size_request(400, 120); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("extending GtkSpinButton"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0.5, 0, 0); $alignment->add($title); $vbox->pack_start($alignment, 0); $vbox->pack_start(new GtkLabel(), 0);
$vbox->pack_start($hbox = new GtkHBox(), 0); $hbox->pack_start(new GtkLabel('Please select a value: '), 0); $spin_button = new mySpinButton(10, 20, 2); // note 1
$spin_button->set_editable(0); // note 2
$hbox->pack_start($spin_button, 0);
$window->show_all(); Gtk::main();
class mySpinButton extends GtkSpinButton { // note 3
function __construct($min=0, $max=0, $step_incr=0) { parent::__construct();
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Create a new instance of your mySpinButton class.
- Set the entry field to be non-editable.
- Definition of the mySpinButton class.
- Create a new GtkAdjustment.
- Bind it to the GtkSpinButton.
- Set the initial value.
Related Links
User reviews Average user ratings: 5.0 (from 1 user) Note: You have to be a registered member to leave a comment. Free registration here. |
October 08, 2008 4:24am
A very quick response - and with example code. I tried for hours to figure it out.