How to attach a Gtk::Menu to a Gtk::Widget?

Hello everybody,

I am trying to create a Gtk::Window containing a button and then connect the button to a callback function that creates a Gtk::Menu and attaches the Gtk::Menu to the button. When the user clicks on the button, a Gtk::Menu will appear next to the Gtk::Button.

Here is my on_button_clicked() function, which append an EMPTY Gtk::MenuItem into the Gtk::Menu and attach the menu with the button:

void TopWin::on_button_clicked() {
  menu.append(menuitem);  //menuitem is an empty Gtk::MenuItem

However, my program was not compiled. Here is the output of g++:

error: ‘void Gtk::Menu::attach_to_widget(Gtk::Widget&)’ is protected 

After receiving this error I tried to go through Gtk::UIManager, Gtk::Widget references to find another way to attach the Gtk::Menu to Gtk::Widget but I did not see anything similar. Does anyone know a better way to handle the situation? 

Also note here that menuitem is EMPTY, since I am planning on adding a Gtk::HScale to it so that the popup menu will contain a Gtk::HScale instead of traditional Gtk::MenuItem.

Thank you for reading my message!! Have a good day!!

Best regards,

Phong Cao

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]