Skip to main content

basic/
basic.rs

1use qtrs::*;
2
3fn main() {
4    let app = Application::new();
5
6    // Build a top-level window
7    let mut window = Widget::new()
8        .title("Hello, qtrs!")
9        .size(400, 300)
10        .icon("assets/icon.png")
11        .build();
12
13    // Put widgets in a vertical layout
14    let mut layout = VBoxLayout::with_parent(&window);
15
16    let btn = PushButton::new("Click me")
17        .on_clicked(|| println!("clicked!"))
18        .build();
19    let label = Label::new("Welcome!").build();
20
21    // Layout takes ownership of widgets
22    layout.add_widget(Box::new(btn));
23    layout.add_widget(Box::new(label));
24
25    // Install layout, then show the window
26    window.set_vlayout(layout.layout_ptr());
27    window.show();
28
29    // Enter the Qt event loop
30    app.exec();
31}