M
Markus Pitha
Hello,
I have a method which creates a lot of buttons in a GUI window.
My target is it to change the button's label from "0" to "1" from the
just clicked button. (There is a set_label method for Gtk::Button).
My problem is that I don't know how to access the method of a
Gtk::Button through a method written by myself.
Here is the example:
//This method creates the button window (for my problem here not needed)
void GUIMenu:nInputClick() {
Gtk::Table table;
Gtk::HBox hbox;
createTable(table);
matrixWindow.set_title("Adjazenzmatrix");
hbox.pack_start(table);
matrixWindow.add(hbox);
matrixWindow.set_resizable(false);
matrixWindow.show_all();
Gtk::Main::run(matrixWindow);
}
//This method is invoked when a button is clicked. How can I access the
button from the bottom method with this method to change the label of
the button?
void GUIMenu:nMatrixClick(int j, int i, Gtk::Button &button) {
button.set_label(" 1 ");
}
//private
void GUIMenu::createTable(Gtk::Table &tab) {
int knotenAnzahl = spinbutton.get_value_as_int();
for(int i = 0; i < knotenAnzahl; i++) {
for(int j = 0; j < knotenAnzahl; j++) {
Gtk::Button* pButton = Gtk::manage(new Gtk::Button(" 0 "));
if (i == j)
pButton->modify_bg(Gtk::STATE_NORMAL, Gdk::Color("red"));
tab.attach(*pButton, j, j+1, i, i+1);
pButton->signal_clicked().connect(sigc::bind<int, int>
(sigc::mem_fun(*this, &GUIMenu:nMatrixClick), j,
i, pButton));
}
}
}
Thanks,
Markus
I have a method which creates a lot of buttons in a GUI window.
My target is it to change the button's label from "0" to "1" from the
just clicked button. (There is a set_label method for Gtk::Button).
My problem is that I don't know how to access the method of a
Gtk::Button through a method written by myself.
Here is the example:
//This method creates the button window (for my problem here not needed)
void GUIMenu:nInputClick() {
Gtk::Table table;
Gtk::HBox hbox;
createTable(table);
matrixWindow.set_title("Adjazenzmatrix");
hbox.pack_start(table);
matrixWindow.add(hbox);
matrixWindow.set_resizable(false);
matrixWindow.show_all();
Gtk::Main::run(matrixWindow);
}
//This method is invoked when a button is clicked. How can I access the
button from the bottom method with this method to change the label of
the button?
void GUIMenu:nMatrixClick(int j, int i, Gtk::Button &button) {
button.set_label(" 1 ");
}
//private
void GUIMenu::createTable(Gtk::Table &tab) {
int knotenAnzahl = spinbutton.get_value_as_int();
for(int i = 0; i < knotenAnzahl; i++) {
for(int j = 0; j < knotenAnzahl; j++) {
Gtk::Button* pButton = Gtk::manage(new Gtk::Button(" 0 "));
if (i == j)
pButton->modify_bg(Gtk::STATE_NORMAL, Gdk::Color("red"));
tab.attach(*pButton, j, j+1, i, i+1);
pButton->signal_clicked().connect(sigc::bind<int, int>
(sigc::mem_fun(*this, &GUIMenu:nMatrixClick), j,
i, pButton));
}
}
}
Thanks,
Markus