Skip to main content

Crate qtrs

Crate qtrs 

Source
Expand description

§qtrs — Rust-style Qt6 bindings

A type-safe, builder-pattern-driven Qt6 GUI library for Rust. Built on cxx for C++ interop, with RAII memory management, signal/callback bridging, and a fluent builder API.

§Installation

Add to your Cargo.toml:

[dependencies]
qtrs = "0.1.0"

§Features

  • ui — enables .ui file loading via QUiLoader. Requires qt6-tools-dev (Debian) or equivalent.

§Enable features:

[dependencies]
qtrs = { version = "0.1.0", features = ["ui"] }

§Design principles

  • Builder pattern everywhere — chain .title("X").size(800, 600).show()
  • RAII cleanup — widgets are automatically deleted on Drop, with parent-child awareness (widgets with a Qt parent skip C++ deletion to avoid double-free).
  • Type-safe layout ownership — adding a widget to a layout transfers ownership; the layout drops its children when it goes out of scope.
  • Zero-cost signal bridging — Qt signals invoke Rust closures via a single global trampoline; context tokens are plain u64 values.

§Architecture

LayerCrate moduleWhat it does
C++ glue(internal)Inline wrappers around Qt6 API
cxx bridgeffiOpaque C++ types + extern "C++" signatures
Safe wrappersapp, widget, button, label, input, layoutBuilder patterns, RAII, signals
Public API(this module)Re-exports of all safe types
TypeQt classSignals
ApplicationQApplication
WidgetQWidget
PushButtonQPushButtonon_clicked
LabelQLabel
LineEditQLineEditon_return_pressed
CheckBoxQCheckBoxon_toggled(bool)
ComboBoxQComboBoxon_current_text_changed
on_current_index_changed(i32)
TextEditQTextEditon_text_changed
SliderQSlideron_value_changed(i32)
ProgressBarQProgressBar
RadioButtonQRadioButtonon_toggled(bool)
GroupBoxQGroupBox
TabWidgetQTabWidgeton_current_changed(i32)
SpinBoxQSpinBoxon_value_changed(i32)
MenuQMenu
MenuBarQMenuBar
TimerQTimeron_timeout
single_shot(ms, fn)
VBoxLayoutQVBoxLayout
HBoxLayoutQHBoxLayout
GridLayoutQGridLayout
dialogQMessageBoxinformation, warning, critical, question

§Quick example

use qtrs::prelude::*;

fn main() {
    let app = Application::new();

    let mut window = Widget::new()
        .title("Hello, qtrs!")
        .size(400, 300)
        .build();

    let mut layout = VBoxLayout::with_parent(&window);

    let btn = PushButton::new("Click me")
        .on_clicked(|| println!("clicked!"))
        .build();
    let label = Label::new("Welcome!").build();

    layout.add_widget(Box::new(btn));
    layout.add_widget(Box::new(label));

    window.set_vlayout(layout.layout_ptr());
    window.show();

    app.exec();
}

§Thread safety

Qt GUI classes are not thread-safe. All widget creation, mutation, and the event loop must happen on the main thread. This library does not add any synchronisation — you are responsible for staying on the right thread, just as in C++ Qt.

§Linking

Qt6 (Core, Gui, Widgets) must be installed with development headers. The build script uses pkg-config to locate them. If you see Qt6 Library is not installed!, install the qt6-base-dev package (or equivalent) for your distribution.

Re-exports§

pub use app::Application;
pub use button::PushButton;
pub use checkbox::CheckBox;
pub use combobox::ComboBox;
pub use grid::GridLayout;
pub use input::LineEdit;
pub use label::Label;
pub use layout::AsLayout;
pub use layout::HBoxLayout;
pub use layout::VBoxLayout;
pub use slider::Slider;
pub use textedit::TextEdit;
pub use timer::Timer;
pub use widget::AsWidget;
pub use widget::FoundWidget;
pub use widget::Widget;
pub use widget::WidgetKind;
pub use progressbar::ProgressBar;
pub use radiobutton::RadioButton;
pub use groupbox::GroupBox;
pub use tabwidget::TabWidget;
pub use spinbox::SpinBox;
pub use menu::Menu;
pub use menu::MenuBar;

Modules§

app
Qt application singleton.
button
Push-button widget with click callbacks.
checkbox
Checkbox widget with toggle callback.
combobox
Drop-down combo box widget.
dialog
Standard dialog boxes (QMessageBox convenience wrappers).
ffi
grid
Grid layout for arranging widgets in rows and columns.
groupbox
Group box widget.
input
Single-line text input widget.
label
Static text label widget.
layout
Layout managers for arranging widgets.
menu
Menu and menu bar widgets.
prelude
Prelude: commonly used types and traits.
progressbar
Progress bar widget.
radiobutton
Radio button widget.
slider
Slider widget for selecting a value from a range.
spinbox
Spin box widget for integer input.
tabwidget
Tab widget for multi-page interfaces.
textedit
Multi-line text editor widget.
timer
Timer for delayed or periodic callbacks.
widget
Base widget type and the AsWidget trait.