Signal of a button dynamically created
Hi, I'm building a popup window that has a Gtk::Grid inside it. The first row has a form with three Gtk::Entry and a button to add the information to the program. The rest of the rows has the items created before in that way (just with Gtk::Label) and a button to remove the information. Like this: |--| | Gtk::Entry | Gtk::Entry | Gtk::Entry | Gtk::Button (add) | |--| |--- rows dynamically added --| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| ... The point here is: how can I know what button was pressed in order to remove a row? Thanks! :) Borja. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Signal of a button dynamically created
I'm not experienced but here's a quick idea: Create a new derived Button class which handles its own click by overriding the virtual method, and in that method it emits a signal which passes the button ID/row number as a parameter. Then listen to this signal from all buttons :-) :כתב Borja Mon Serrano, 2013-10-28 17:22 בתאריך Hi, I'm building a popup window that has a Gtk::Grid inside it. The first row has a form with three Gtk::Entry and a button to add the information to the program. The rest of the rows has the items created before in that way (just with Gtk::Label) and a button to remove the information. Like this: |--| | Gtk::Entry | Gtk::Entry | Gtk::Entry | Gtk::Button (add) | |--| |--- rows dynamically added --| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| ... The point here is: how can I know what button was pressed in order to remove a row? Thanks! :) Borja. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list [1] Links: -- [1] https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Signal of a button dynamically created
Le 28/10/2013 16:22, Borja Mon Serrano a écrit : [...] The point here is: how can I know what button was pressed in order to remove a row? When you connect a handler to a signal, there is a data parameter, just pass in some info identifying the row through it: g_signal_connect(button, clicked, G_CALLBACK(your_handler), GUINT_TO_POINTER(row_id)) Alternatively, you can add arbitrary data associated with a widget, using ::set_data(), so you could pass the row info through this too: g_object_set_data(button, row-id, GUINT_TO_POINTER(row_id)); Regards, Colomban ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
RE: Signal of a button dynamically created
I think the best thing you can do is associate a number when you connect the button response to a method like this: my_button.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, my_class::OnMyButtonClicked),iNumber)); The only thing you have to take into account is that the response method changes from the standard one. If the method to be associated to a click event of a button is the following: void on_my_clicked() When you use sigc::bind the method changes and it should be like this void OnMyButtonClicked(int x) I hope this helps you, Kind regards, Jon Zabala Date: Mon, 28 Oct 2013 17:29:18 +0200 From: fr33domlo...@mailoo.org To: gtk-app-devel-list@gnome.org Subject: Re: Signal of a button dynamically created I'm not experienced but here's a quick idea: Create a new derived Button class which handles its own click by overriding the virtual method, and in that method it emits a signal which passes the button ID/row number as a parameter. Then listen to this signal from all buttons :-) :כתב Borja Mon Serrano, 2013-10-28 17:22 בתאריך Hi, I'm building a popup window that has a Gtk::Grid inside it. The first row has a form with three Gtk::Entry and a button to add the information to the program. The rest of the rows has the items created before in that way (just with Gtk::Label) and a button to remove the information. Like this: |--| | Gtk::Entry | Gtk::Entry | Gtk::Entry | Gtk::Button (add) | |--| |--- rows dynamically added --| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| | Gtk::Label | Gtk::Label | Gtk::Label | Gtk::Button (remove) | |--| ... The point here is: how can I know what button was pressed in order to remove a row? Thanks! :) Borja. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list [1] Links: -- [1] https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkEntry ... change size
Mariano Gaudix wrote: I can not change the size to GtkEntry . I am using Gtk 3.6 . I need a GtkEntry small , for my graphic interface . GTK expands widgets to fill space by default so setting widget size has no visible effect. You need to disable expansion. I'll add a general disclaimer that you should not hard-code widget size unless you absolutely must. Allowing widgets to expand helps your app work on different screen sizes and shapes. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Signal of a button dynamically created
Borja Mon Serrano wrote: The point here is: how can I know what button was pressed in order to remove a row? You need to attach to the clicked signal on each button[1]. Each button could call a separate function or you can pass a pointer to different values to know which button is which. [1] https://developer.gnome.org/gtkmm-tutorial/unstable/sec-connecting-signal-handlers.html.en ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Signal of a button dynamically created
On Mon, Oct 28, 2013 at 04:22:38PM +0100, Borja Mon Serrano wrote: The point here is: how can I know what button was pressed in order to remove a row? (a) by passing something that identifies the button within user_data when you do g_signal_connect... (b) using something along the lines of g_object_set_data(button, id, ...) to give each button an identifier and retrieving it in the signal handler (c) by keeping the buttons in some data structure (list, hash table,...) and identifying them by the object address in the signal handler There are other methods, but these are probably typical. Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Signal of a button dynamically created
Thank you all guys, you're incredible! :) I've finally implemented the Jon Zabala's answer, I think it's the easiest. Thank you again!! ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkEntry ... change size
¿ how I disable expansion ? I used the sentences . gtk_widget_set_vexpand (GTK_WIDGET(entry ) , FALSE ) ; gtk_widget_set_hexpand (GTK_WIDGET(entry ) , FALSE ) ; But these sentencesdon't run . 2013/10/28 Michael Cronenworth m...@cchtml.com Mariano Gaudix wrote: I can not change the size to GtkEntry . I am using Gtk 3.6 . I need a GtkEntry small , for my graphic interface . GTK expands widgets to fill space by default so setting widget size has no visible effect. You need to disable expansion. I'll add a general disclaimer that you should not hard-code widget size unless you absolutely must. Allowing widgets to expand helps your app work on different screen sizes and shapes. __**_ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/**mailman/listinfo/gtk-app-**devel-listhttps://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkEntry ... change size
Mariano Gaudix wrote: ¿ how I disable expansion ? I used the sentences . gtk_widget_set_vexpand (GTK_WIDGET(entry ) , FALSE ) ; gtk_widget_set_hexpand (GTK_WIDGET(entry ) , FALSE ) ; But these sentencesdon't run . I know those are the new GTK3 functions, but I still mainly use GTK2. Try: gtk_container_add( GTK_CONTAINER( hBox ), entry ); gtk_box_set_child_packing( GTK_BOX( hBox ), entry, FALSE, TRUE, 0, GTK_PACK_START ); gtk_widget_show( entry ); ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkEntry ... change size
On 10/28/2013 08:55 PM, Mariano Gaudix wrote: The GtkEntry continuous big . gtk_box_set_child_packing( GTK_BOX( box ), entry,FALSE, TRUE, 0, GTK_PACK_START ); the sentence don't work . You need a widget adjacent to your entry to take up the space you don't want filled by your entry... (say a blank label widget) ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list