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.2.5"§Features
ui— enables.uifile loading viaQUiLoader. Requiresqt6-tools-dev(Debian) or equivalent.
§Enable features:
[dependencies]
qtrs = { version = "0.2.5", 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
u64values.
§Architecture
| Layer | Crate module | What it does |
|---|---|---|
| C++ glue | (internal) | Inline wrappers around Qt6 API |
| cxx bridge | ffi | Opaque C++ types + extern "C++" signatures |
| Safe wrappers | app, widget, button, label, input, layout | Builder patterns, RAII, signals |
| Public API | (this module) | Re-exports of all safe types |
§Widget gallery
| Type | Qt class | Signals |
|---|---|---|
Application | QApplication | — |
Widget | QWidget | — |
PushButton | QPushButton | on_clicked |
Label | QLabel | — |
LineEdit | QLineEdit | on_return_pressed |
CheckBox | QCheckBox | on_toggled(bool) |
ComboBox | QComboBox | on_current_text_changedon_current_index_changed(i32) |
TextEdit | QTextEdit | on_text_changed |
Slider | QSlider | on_value_changed(i32) |
ProgressBar | QProgressBar | — |
RadioButton | QRadioButton | on_toggled(bool) |
GroupBox | QGroupBox | — |
TabWidget | QTabWidget | on_current_changed(i32) |
SpinBox | QSpinBox | on_value_changed(i32) |
Menu | QMenu | — |
MenuBar | QMenuBar | — |
Timer | QTimer | on_timeoutsingle_shot(ms, fn) |
VBoxLayout | QVBoxLayout | — |
HBoxLayout | QHBoxLayout | — |
GridLayout | QGridLayout | — |
FileDialog | QFileDialog | open_file, save_file, select_directory (static) |
dialog | QMessageBox | information, 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 qmake to locate them. If you see
Qt not found!, 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;pub use conn::ConnectExt;pub use conn::ConnType;pub use conn::SignalMeta;pub use conn::SlotMeta;pub use filedialog::FileDialog;pub use point::Point;
Modules§
- app
- Qt application singleton.
- button
- Push-button widget with click callbacks.
- checkbox
- Checkbox widget with toggle callback.
- combobox
- Drop-down combo box widget.
- conn
- Type-safe signal-slot connection API
- dialog
- Standard dialog boxes (QMessageBox convenience wrappers).
- ffi
- filedialog
- File dialog for opening and saving files.
- 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.
- point
- 2D point representation for widget positioning.
- prelude
- Prelude: commonly used types and traits.
- progressbar
- Progress bar widget.
- radiobutton
- Radio button widget.
- signals
- Compile-time signal and slot identifiers
- 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
AsWidgettrait.