Time Until Wedding
Days
Hours
Minutes
Seconds
 
Navigation
 
Search
 
My Usable Projects
 
Reading...
 
Listening...
 
Random Image
RyansCam_057.jpg
 
Archives
 
Me. Elsewhere.
 
Feeds and Such

Google Reader or Homepage
Add to My Yahoo!
Add to Technorati Favorites!
Bookmark del.icio.us
Bookmark Furl
Bookmark Spurl
 
Darcy
 
Things I Like
Amarok Media Player
 
License
 
GTK Tooltips On Notebook Tab Labels

Here’s a non-obvious (or to me at least) trick to get tooltips onto a Gtk::Notebook tab. It took some searching, but essentially, you just add the Gtk::Label to a Gtk::EventBox and add that to the tab instead. Then you attach the tool tip to the Gtk::EventBox instead of the Gtk::Label.

Here’s an example. I couldn’t get my example to compile, the linker was going crazy, but I’m 99% sure that it’s fine. I’m probably just not seeing one glaring error. Let me know if you find it. The important stuff is all there, even if it won’t build.

main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <gtkmm/main.h>
#include "nbtt.h"
 
using namespace std;
 
int main (int argc, char *argv[]) {
 
  Gtk::Main kit (argc, argv);
  Nbtt notebookWindow;
  Gtk::Main::run(notebookWindow);
 
  return 0;
}

nbtt.cpp

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
#include <gtkmm/window.h>
#include "nbtt.h"
 
using namespace std;
 
Nbtt::Nbtt() {
 
  set_title("Notebook Tabs With Labels!");
  set_border_width(10);
  set_default_size(400, 200);
 
  lblTabOne.set_text("Tab 1");
  lblTabTwo.set_text("Tab 2");
  lblTabThree.set_text("Tab 3");
 
  ebTabOne.add(lblTabOne);
  ebTabTwo.add(lblTabTwo);
  ebTabThree.add(lblTabThree);
 
  toolTips.set_tip(ebTabOne,"Tab to page one.");
  toolTips.set_tip(ebTabTwo,"Tab to page two.");
  toolTips.set_tip(ebTabThree,"Tab to page three.");
 
  exNotebook.append_page(pageOne, ebTabOne);
  exNotebook.append_page(pageTwo, "Second");
 
  show_all();
}

nbtt.h

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
33
34
35
36
37
38
#ifndef NBTT_H
#define NBTT_H
 
#include <gtkmm/window.h>
#include <gtkmm/notebook.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/label.h>
#include <gtkmm/tooltips.h>
 
using namespace std;
 
class Nbtt;
 
class Nbtt : public Gtk::Window {
 
  public:
    Nbtt();
 
  private:
    Gtk::Notebook exNotebook;
 
    Gtk::EventBox ebTabOne;
    Gtk::EventBox ebTabTwo;
    Gtk::EventBox ebTabThree;
 
    Gtk::Label lblTabOne;
    Gtk::Label lblTabTwo;
    Gtk::Label lblTabThree;
 
    Gtk::Tooltips toolTips;
 
    Gtk::Label pageOne;
    Gtk::Label pageTwo;
    Gtk::Label pageThree;
 
};
 
#endif // NBTT_H

I found this trick in the gnome-list@gnome.org history. The thread starts here if you want to read the exchange.

Posted August 22nd, 2007 - Permalink
Categories: C++ - GTK+ - Programming - Work
You can leave a comment, or trackback from your own site.
 
Adjacent Posts
 
Comments