| Crates.io | shawon |
| lib.rs | shawon |
| version | 0.1.6 |
| created_at | 2025-05-17 10:43:14.982876+00 |
| updated_at | 2025-05-18 05:44:55.175997+00 |
| description | A lightweight Rust wrapper for Qt, providing a simple and ergonomic way to create cross-platform GUI applications |
| homepage | |
| repository | https://github.com/algoscienceacademy/shawon |
| max_upload_size | |
| id | 1677783 |
| size | 185,187 |
ShawonUI is a lightweight Rust wrapper for Qt, providing a simple and ergonomic way to create cross-platform GUI applications in Rust without external dependencies.
Add ShawonUI to your Cargo.toml:
[dependencies]
shawon = "0.1.5
use shawon::{Application, Button, Label, Window};
use std::rc::Rc;
fn main() {
// Initialize the application
let app = Application::new();
// Create a window
let window = Rc::new(Window::new("Hello ShawonUI", 400, 200));
// Create a label
let label = Label::new("Hello, world!");
window.add_label(&label);
// Create a button
let mut button = Button::new("Click Me");
// Clone window for the closure
let window_clone = Rc::clone(&window);
// Set button click callback
button.set_callback(move || {
window_clone.show_message_box(
shawonui::MessageBoxIcon::Information,
"Hello",
"Hello from ShawonUI!"
);
});
window.add_button(&button);
// Show the window
window.show();
// Run the application
app.exec();
}
ShawonUI provides the following widget types:
Window - Main application window or containerButton - Standard push buttonLabel - Display text or imagesTextEntry - Single-line text inputCheckBox - Checkbox with text labelRadioButton - Radio button with text labelGroupBox - Container with border and titleTabWidget - Container with tabbed interfaceListWidget - List of itemsTreeWidget - Hierarchical tree viewTableWidget - Grid of cellsSlider - Sliding value selectorComboBox - Dropdown listProgressBar - Progress indicatorSplitter - Resizable split viewShawonUI supports horizontal layouts to arrange widgets:
// Create a layout
let layout = HBoxLayout::new();
// Add widgets to the layout
layout.add_label(&label);
layout.add_button(&button);
// Add the layout to a window or group box
window.add_layout(&layout);
ShawonUI supports Qt's CSS-like styling system:
// Apply a stylesheet to a widget
button.set_stylesheet("
background-color: #0078d7;
color: white;
border: none;
border-radius: 4px;
padding: 5px 15px;
");
// Apply a stylesheet to the entire application
app.set_stylesheet("
QWidget {
font-family: 'Segoe UI', Arial, sans-serif;
font-size: 10pt;
}
QPushButton {
background-color: #0078d7;
color: white;
}
");
let list_widget = ListWidget::new();
list_widget.add_item("Item 1");
list_widget.add_item("Item 2");
list_widget.set_item_clicked_callback(|row| {
println!("Clicked on row {}", row);
});
let mut tree_widget = TreeWidget::new();
tree_widget.set_headers(&["Name", "Description"]);
let parent = tree_widget.add_top_item("Parent");
let child = tree_widget.add_child_item(parent, "Child").unwrap();
tree_widget.set_item_text(parent, Some(child), 1, "Description");
let table_widget = TableWidget::new(3, 3);
table_widget.set_horizontal_headers(&["Column 1", "Column 2", "Column 3"]);
table_widget.set_cell_text(0, 0, "Cell 1,1");
table_widget.set_cell_text(0, 1, "Cell 1,2");
QAbstractButton provides the basic functionality for button widgets. It can be used for clickable buttons:
use shawon::{Application, QAbstractButton, QWidget};
fn main() {
let app = Application::new();
let window = QWidget::new();
let button = QAbstractButton::new();
button.set_text("Click Me");
button.set_parent(&window);
button.on_clicked(|| {
println!("Button was clicked!");
});
window.show();
app.exec();
}
// File open dialog
if let Some(path) = window.show_open_file_dialog("Open File", "", "All Files (*.*)") {
println!("Selected file: {}", path);
}
// Message box
window.show_message_box(
MessageBoxIcon::Information,
"Information",
"This is an information message."
);
ShawonUI uses a C++ layer to interface with Qt, and exposes a pure Rust API. The C++ code is compiled during the build process, and linked with your Rust application. This approach allows for a clean Rust API while leveraging the power and flexibility of Qt.
MIT License
Contributions are welcome! Feel free to open issues or submit pull requests.