RubyQt6
Ruby Bindings for libQt6, providing access to the Qt framework.
Requirements
- Ruby 3.4+
- Qt 6.9+
Installation
See INSTALL.md for installation instructions.
Usage
require 'qt6/qtwidgets'
# Import all components from QtCore, QtGui and QtWidgets modules
RubyQt6.load_defaults
# Create a widget inherit from RubyQt6::Bando::<...>, so that we
# can use `q_object` macro to define signals and slots.
class MyWidget < RubyQt6::Bando::QWidget
q_object do
signal "quit_clicked()" # signals are automatically generated by RubyQt6, must not be implemented
slot "on_slider_value_changed(int)" # slots must be implemented later
end
def initialize
super # NOTE: You must call `super` first
quit = QPushButton.new('Quit')
quit.set_font(QFont.new('Times', 18, QFont::Bold))
@lcd = QLCDNumber.new(2)
slider = QSlider.new(Qt::Horizontal)
slider.set_range(0, 99)
slider.set_value(0)
layout = QVBoxLayout.new
layout.add_widget(quit)
layout.add_widget(@lcd)
layout.add_widget(slider)
set_layout(layout)
quit.clicked.connect(self, :quit_clicked)
slider.value_changed.connect(self, :on_slider_value_changed)
end
def on_slider_value_changed(value)
@lcd.display(value)
end
end
if __FILE__ == $PROGRAM_NAME
app = QApplication.new
widget = MyWidget.new
widget.quit_clicked.connect(app, :quit)
widget.show
app.exec
endMore examples can be found in examples.
License
The RubyQt6 library is licensed under the LGPL-3.0 WITH LGPL-3.0-linking-exception.
You must also meet your Qt license obligations.