handle radiobutton click event (QT)

8 days ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 05 Apr 2025 11:21:02 +0200 (8 days ago)
changeset 551
0e543e1d060e
parent 550
0412c4c1048e
child 552
131059d41671

handle radiobutton click event (QT)

ui/qt/button.cpp file | annotate | diff | comparison | revisions
ui/qt/toolkit.cpp file | annotate | diff | comparison | revisions
--- a/ui/qt/button.cpp	Fri Apr 04 22:16:29 2025 +0200
+++ b/ui/qt/button.cpp	Sat Apr 05 11:21:02 2025 +0200
@@ -165,6 +165,14 @@
 }
 
 
+static void radiobutton_event(UiEvent *event, UiEventWrapper *wrapper) {
+    if(wrapper->var) {
+        UiInteger *value = wrapper->var->value;
+        event->eventdata = value;
+        event->intval = ui_get(value);
+    }
+}
+
 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) {
     UiContainerPrivate *ctn = ui_obj_container(obj);
     UI_APPLY_LAYOUT(ctn->layout, args);
@@ -190,9 +198,12 @@
         value->set = ui_radiobutton_set;
     }
     
-    // TODO: unbind var/remove button from buttongroup when the button is destroyed
-    // TODO: implement callback
-    // TODO: implement value observer
+    UiEventWrapper *event = new UiEventWrapper(obj, args.onchange, args.onchangedata);
+    event->var = var;
+    event->customdata1 = button;
+    event->prepare_event = togglebutton_event;
+    button->connect(button, SIGNAL(clicked()), event, SLOT(slot()));
+    button->connect(button, SIGNAL(destroyed()), event, SLOT(destroy()));
     
     ctn->add(button, false);
     
--- a/ui/qt/toolkit.cpp	Fri Apr 04 22:16:29 2025 +0200
+++ b/ui/qt/toolkit.cpp	Sat Apr 05 11:21:02 2025 +0200
@@ -161,7 +161,7 @@
 }
 
 UiAction::~UiAction() {
-    
+    // TODO: unbind var
 }
 
 void UiAction::trigger() {

mercurial