Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add tooltips to the entries in a GTK ComboBox?

Is there any way to add tooltips to the individual entries of a combobox? I'd like it so that when the combobox is open (and only when it is open) and the user mouses over one of the possible selections, additional information would show up in a tooltip.

It seems like there aren't any real widgets within a combobox to add the tooltips to. Is the only way to do this to somehow put widgets (like labels) in the entries of the combobox?

like image 883
Jeremy Avatar asked Mar 13 '12 21:03

Jeremy


1 Answers

I think you are on the right track with putting labels in the combobox and adding tooltips to the labels. You can create a custom list store for the combo box which contains the labels. This is an attempt at it, not in pygtk but in guile-gnome (my native habitat, sorry! I may try a translation to pygtk later) It runs, but not correctly yet, the labels are not being displayed.

Actually, getting the gtkcombobox to display widgets (rather than just text) seems possible but difficult - see here for example. It may require a custom GtkCellRendererWidget class that is not part of the base library.

(use-modules (oop goops)
         (gnome gtk))

(define w (make <gtk-window> #:title "combo demo"))
(connect w 'destroy (lambda args (gtk-main-quit)))

(define combo (make <gtk-combo-box>))
(define list-store (gtk-list-store-new `(,<gtk-label>)))
(set combo 'model list-store)
(define tooltips (gtk-tooltips-new))

(define (list-store-append-label-with-tooltip list-store text tip)
  (let ((label (make <gtk-label> #:label "hello")))
    (gtk-tooltips-set-tip tooltips label tip #f)
    (gtk-list-store-set-value
     list-store
     (gtk-list-store-append list-store)
     0
     label)))

(list-store-append-label-with-tooltip list-store "hello" "first word")
(list-store-append-label-with-tooltip list-store "world" "second word")

(add w combo)
(show-all w)

(gtk-main)
like image 97
gcbenison Avatar answered Nov 13 '22 10:11

gcbenison