add button (QT)

7 days ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 26 Mar 2025 21:54:42 +0100 (7 days ago)
changeset 520
ea1bba55de44
parent 519
8884c7fbe4cb
child 521
6e3e1fa6dfcc

add button (QT)

application/main.c file | annotate | diff | comparison | revisions
ui/qt/button.cpp file | annotate | diff | comparison | revisions
ui/qt/container.cpp file | annotate | diff | comparison | revisions
ui/qt/container.h file | annotate | diff | comparison | revisions
ui/qt/window.cpp file | annotate | diff | comparison | revisions
--- a/application/main.c	Wed Mar 26 21:47:04 2025 +0100
+++ b/application/main.c	Wed Mar 26 21:54:42 2025 +0100
@@ -775,7 +775,9 @@
 
 void application_startup(UiEvent *event, void *data) {
     UiObject *obj = ui_window("My Window", NULL);
-    
+    ui_button(obj, .label = "Button 1");
+    ui_button(obj, .label = "Button 2");
+    ui_button(obj, .label = "Button 3");
     ui_show(obj);
 }
 
--- a/ui/qt/button.cpp	Wed Mar 26 21:47:04 2025 +0100
+++ b/ui/qt/button.cpp	Wed Mar 26 21:54:42 2025 +0100
@@ -30,3 +30,20 @@
 #include "container.h"
 #include "toolkit.h"
 
+UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) {
+    UiContainerPrivate *ctn = ui_obj_container(obj);
+    UI_APPLY_LAYOUT(ctn->layout, args);
+    
+    QString str = QString::fromUtf8(args.label);
+    QPushButton *button = new QPushButton(str);
+    
+    if(args.onclick) {
+        UiEventWrapper *event = new UiEventWrapper(obj, args.onclick, args.onclickdata);
+        button->connect(button, SIGNAL(clicked()), event, SLOT(slot()));
+    }
+    
+    ctn->add(button, false);
+    
+    return button;
+}
+
--- a/ui/qt/container.cpp	Wed Mar 26 21:47:04 2025 +0100
+++ b/ui/qt/container.cpp	Wed Mar 26 21:54:42 2025 +0100
@@ -39,7 +39,7 @@
     delete ct;
 }
 
-static void add_container(UiObject *obj, UiContainerPrivate *ct) {
+void ui_container_add(UiObject *obj, UiContainerPrivate *ct) {
     UiContainerX *container = (UiContainerX*)ui_malloc(obj->ctx, sizeof(UiContainerX));
     container->close = 0;
     container->container = ct;
--- a/ui/qt/container.h	Wed Mar 26 21:47:04 2025 +0100
+++ b/ui/qt/container.h	Wed Mar 26 21:54:42 2025 +0100
@@ -54,7 +54,7 @@
 #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE)
 #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE)
 
-#define ui_obj_container(obj) (UiContainerPrivate*)obj->container_end
+#define ui_obj_container(obj) (UiContainerPrivate*)((UiContainerX*)obj->container_end)->container
 
 typedef enum UiLayoutBool {
     UI_LAYOUT_UNDEFINED = 0,
@@ -106,6 +106,8 @@
     virtual void add(QWidget *widget, bool fill);
 };
 
+void ui_container_add(UiObject *obj, UiContainerPrivate *ct);
+
 
 #endif	/* CONTAINER_H */
 
--- a/ui/qt/window.cpp	Wed Mar 26 21:47:04 2025 +0100
+++ b/ui/qt/window.cpp	Wed Mar 26 21:54:42 2025 +0100
@@ -60,7 +60,7 @@
     QWidget *boxWidget = new QWidget();
     boxWidget->setLayout(box);
     window->setCentralWidget(boxWidget);
-    //obj->container = new UiBoxContainer(box);
+    ui_container_add(obj, new UiBoxContainer(box));
     
     obj->widget = window;
     return obj;

mercurial