Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Gtkmm: Setting current tab label?

  1. #1
    Join Date
    Mar 2008
    Location
    Ireland
    Beans
    838
    Distro
    Ubuntu 17.10 Artful Aardvark

    Gtkmm: Setting current tab label?

    I don't know why this seems so difficult but all I want to do is set the current tab label/title. Here is what I have so far:

    Code:
            Gtk::Widget& widget = m_Notebook.get_current_page();
            Glib::ustring label = "TEST";
            m_Notebook.set_tab_label(widget, label);
    The errors shown don't make much sense to me. :/

    mainwindow.cc:545:59: error: invalid initialization of non-const reference of type ‘Gtk::Widget&’ from an rvalue of type ‘int’
    mainwindow.cc:547:47: error: no matching function for call to ‘Gtk::Notebook::set_tab_label(Gtk::Widget&, Glib::ustring&)’
    mainwindow.cc:547:47: note: candidate is:
    /usr/include/gtkmm-3.0/gtkmm/notebook.h:435:8: note: void Gtk::Notebook::set_tab_label(Gtk::Widget&, Gtk::Widget&)
    /usr/include/gtkmm-3.0/gtkmm/notebook.h:435:8: note: no known conversion for argument 2 from ‘Glib::ustring’ to ‘Gtk::Widget&’
    Any help appreciated!
    Projects - PhotoFlare Image Editor | Xwii | URT-2D | BHR
    Hardware - System 76 - Galago UltraPro

  2. #2
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: Gtkmm: Setting current tab label?

    The get_current_page() method returns the index number of the tab, not a widget:

    https://developer.gnome.org/gtkmm/3....c551ede9015dff

    To get the child widget, you need to pass the index number to get_nth_page(int page_num):

    https://developer.gnome.org/gtkmm/3....40824c53f4c1ad
    Last edited by r-senior; March 7th, 2013 at 04:21 PM. Reason: Changed doc links to gtkmm3
    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

  3. #3
    Join Date
    Mar 2008
    Location
    Ireland
    Beans
    838
    Distro
    Ubuntu 17.10 Artful Aardvark

    Re: Gtkmm: Setting current tab label?

    This is what I have now:

    Code:
            Gtk::Widget& widget = m_Notebook.get_nth_page(
                           m_Notebook.get_current_page());
            Glib::ustring label = "TEST";
            m_Notebook.set_tab_label(widget, label);
    mainwindow.cc:546:53: error: invalid initialization of non-const reference of type ‘Gtk::Widget&’ from an rvalue of type ‘Gtk::Widget*’
    mainwindow.cc:548:47: error: no matching function for call to ‘Gtk::Notebook::set_tab_label(Gtk::Widget&, Glib::ustring&)’
    mainwindow.cc:548:47: note: candidate is:
    /usr/include/gtkmm-3.0/gtkmm/notebook.h:435:8: note: void Gtk::Notebook::set_tab_label(Gtk::Widget&, Gtk::Widget&)
    /usr/include/gtkmm-3.0/gtkmm/notebook.h:435:8: note: no known conversion for argument 2 from ‘Glib::ustring’ to ‘Gtk::Widget&’
    Is this getting any closer?
    Projects - PhotoFlare Image Editor | Xwii | URT-2D | BHR
    Hardware - System 76 - Galago UltraPro

  4. #4
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Gtkmm: Setting current tab label?

    1. Dereference the pointer returned by get_nth_page.
    2. Use set_tab_label_text.
    Code:
            Gtk::Widget& widget = * m_Notebook.get_nth_page(
                           m_Notebook.get_current_page());
            Glib::ustring label = "TEST";
            m_Notebook.set_tab_label_text(widget, label);

  5. #5
    Join Date
    Mar 2008
    Location
    Ireland
    Beans
    838
    Distro
    Ubuntu 17.10 Artful Aardvark

    Re: Gtkmm: Setting current tab label?

    Thanks! (how do I mark this as solved? - not used to the new forum)
    Last edited by fallenshadow; March 7th, 2013 at 06:44 PM.
    Projects - PhotoFlare Image Editor | Xwii | URT-2D | BHR
    Hardware - System 76 - Galago UltraPro

  6. #6
    Join Date
    Mar 2008
    Location
    Ireland
    Beans
    838
    Distro
    Ubuntu 17.10 Artful Aardvark

    Re: Gtkmm: Setting current tab label?

    Oh dear, it seems doing this will get rid of the close button for that tab. What would be the right solution for this?

    Re-add a close button?
    Projects - PhotoFlare Image Editor | Xwii | URT-2D | BHR
    Hardware - System 76 - Galago UltraPro

  7. #7
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: Gtkmm: Setting current tab label?

    I think the trick is that the tab label is a GtkWidget, as opposed to a GtkLabel. The gtk_notebook_set_tab_label_text() function is a convenience function that creates a GtkLabel and sets it as the widget for the tab's label. If you want to have a label and icon as the tab label, you need a container widget, e.g. a GtkBox that contains a GtkLabel and GtkImage/GtkButton. Then you use gtk_notebook_set_tab_label() instead of gtk_notebook_set_tab_label_text(). Expose the label as a property and connect up a signal to the image/button.

    Sorry for quoting the C functions -- you know what I mean.

    There's an example here, not in C++ but GTK is GTK:

    http://stackoverflow.com/questions/2...ab-in-mono-gtk
    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

  8. #8
    Join Date
    Dec 2007
    Location
    Gainesville, Florida
    Beans
    Hidden!
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Gtkmm: Setting current tab label?

    The actual tab widget has changed with your code. Remember you are using a custom function to create a notebook page tab with a close button. If you look at the add_page function in mainwindow.cc you'll see how the initial label is added.

    Code:
    Gtk::Label *label = Gtk::manage(new Gtk::Label(text));
    you need to get a pointer/reference to that label widget to change the text. Something like this may work:
    Code:
    Gtk::Widget& widget = *m_Notebook.get_nth_page(m_Notebook.get_current_page());
    Gtk::Widget label = widget.get_tab_label(widget);
    label.set_text(Glib::ustring("TEST"));
    I'm not sure if this is the correct code but it is the general idea.

  9. #9
    Join Date
    Mar 2008
    Location
    Ireland
    Beans
    838
    Distro
    Ubuntu 17.10 Artful Aardvark

    Re: Gtkmm: Setting current tab label?

    Thanks for the ideas! Yes pbrane this is what I really need to do, change the text of the label without disturbing the close button.

    The widget class seems to have alot of functions: https://developer.gnome.org/gtkmm/3....1_1Widget.html

    However, I can't see ones that would be of any use. As far as I understand widget is a class for general usage with any gtk widget, right? So it may not contain specific functions like what you mentioned.

    mainwindow.cc:551:31: error: ‘class Gtk::Widget’ has no member named ‘get_tab_label’
    mainwindow.cc:552:9: error: ‘class Gtk::Widget’ has no member named ‘set_text’
    Im not so sure its possible to use widget functions to get what I need but you are definitely on the right track idea wise.
    Projects - PhotoFlare Image Editor | Xwii | URT-2D | BHR
    Hardware - System 76 - Galago UltraPro

  10. #10
    Join Date
    Mar 2008
    Location
    Ireland
    Beans
    838
    Distro
    Ubuntu 17.10 Artful Aardvark

    Re: Gtkmm: Setting current tab label?

    Bump :S
    Projects - PhotoFlare Image Editor | Xwii | URT-2D | BHR
    Hardware - System 76 - Galago UltraPro

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •