3.1 QtLua lua libraries

QtLua provides two sets of lua functions:

  • A few general purpose global lua functions are provided. useful when running a lua script in the QtLua environment.

  • A Qt library is provided which gives access to some Qt features which are not available from the Qt meta object system.

3.1.1 Predefined lua functions  

The QtLuaLib library contains the following lua functions:

  • The print() lua function prints all passed values using the State::output signal.

  • The list() lua function prints list of members of given table or global table if no argument is passed.

  • The each() lua function returns a lua iterator which can be used to iterate over lua tables and QtLua UserData objects.

  • The help() lua function can be used to display help about Function based objects:

    >> help(qt.connect)
    usage: qt.connect(qobjectwrapper, "qt_signal_signature()", qobjectwrapper, "qt_slot_signature()")
    qt.connect(qobjectwrapper, "qt_signal_signature()", lua_function)
  • The plugin() function returns a Plugin object loaded from the given plugin bare file name.

  • The qtype() function returns the lua type or userdata QtLua type name of a value.

3.1.2 Qt related functions  

The QtLib library contains some wrapped Qt functions and meta objects. Those are covered in this section.

QObject related functions  

qt.meta table  

The qt.meta table contains wrapped Qt meta objects, useful to access enums and other Qt meta data exposed by Qt.

This list can be extended by adding user defined QObject classes using the State::register_qobject_meta function.

qt.new_qobject function  

The qt.new_qobject function creates a new QObject of given type. It relies on the qt.meta table provided by QtLua (see above):

qobject = qt.new_qobject( qt.meta.QClassName, [ Constructor arguments ] )

Constructor arguments can be provided to use a constructors declared with the Qt Q_INVOKABLE attribute. Most Qt classes have constructors which can be called without argument and can thus be instantiated by this function without requiring the Q_INVOKABLE attribute.

qt.connect function  

The qt.connect function creates a connection between a Qt signal and a Qt slot or between a Qt signal and a lua function:

-- connect signal and slot of given Qt objects
qt.connect(qobject1, "qt_signal_signature()", qobject2, "qt_slot_signature()")

-- connect slot to given lua function
qt.connect(qobject, "qt_signal_signature()", lua_function)

When a lua function is called from a Qt signal, its first argument is the sender object and next arguments are converted signal parameters (see Qt/Lua types conversion).

qt.disconnect function  

The qt.disconnect lua functions can be used to disconnect a Qt slot:

-- disconnect signal and slot of given Qt objects
qt.disconnect(qobjectwrapper1, "qt_signal_signature()", qobjectwrapper2, "qt_slot_signature()")

-- disconnect signal from given lua function
qt.disconnect(qobjectwrapper, "qt_signal_signature()", lua_function)

-- disconnect signal from all connected lua functions
qt.disconnect(qobjectwrapper, "qt_signal_signature()")

qt.meta_type function  

The qt.type function translate between a registered Qt type numeric handle and the associated Qt type name:

type_handle = qt.meta_type( "QTypeName" )
type_name = qt.meta_type( 42 )

See also MetaType class.

GUI related functions  

qt.ui.new_widget function  

The function creates a new widget of given type name using the QUiLoader::createWidget Qt function.

widget = qt.new_widget( "QtClassName", [ "name", parent ] )

Use of the qt.new_qobject function is preferred.

qt.ui.load_ui function  

The qt.load_ui function returns a Qt user interface file loaded using the QUiLoader::load Qt function:

ui = qt.load_ui( "file.ui", [ parent ] )

The qtlua_uic tool can be used instead to compile a Qt .ui file to a lua scripts which creates the user interface.

qt.ui.layout_add function  

The qt.layout_add function is able to bind QWidget objects to various kind of QLayout objects.

-- add a widget to a layout
qt.layout_add( box_layout, widget|layout )
qt.layout_add( grid_layout, widget|layout, row, column, [ row_span, col_span, align ] )
qt.layout_add( form_layout, widget|layout, row, column, [ col_span ] )
qt.layout_add( form_layout, text, widget|layout )

-- set layout of a widget
qt.layout_add( widget, layout )

qt.ui.layout_spacer function  

The qt.layout_spacer function adds a QSpacerItem object to a QLayout object.

qt.ui.layout_spacer( layout, width, height, h QSizePolicy, v QSizePolicy )

qt.ui.attach function  

The qt.ui.attach function invokes one of the following qt functions depending on passed QObject types: QMainWindow::setMenuBar, QMainWindow::setStatusBar, QMainWindow::addToolBar, QMainWindow::addDockWidget, QMainWindow::setCentralWidget, QDockWidget::setWidget, QStackedWidget::addWidget, QToolBar::addWidget, QScrollArea::setWidget, QSplitter::addWidget, QMdiArea::addSubWindow or QWorkspace::addWindow.

qt.ui.menu.add_menu function  

The qt.ui.menu.add_menu function creates and adds a new menu to a QMenu or QMenuBar object. The new QMenu object is returned.

menu = qt.ui.menu.add_menu( menu|menubar, "text", [ "object_name" ] )

qt.ui.menu.add_separator function  

The qt.ui.menu.add_separator function creates and adds a new separator to a QMenu or QToolBar.

sep = qt.ui.menu.add_separator( menu|toolbar, [ "object_name" ] )

qt.ui.menu.add_action function  

The qt.ui.menu.add_action function creates and adds a new QAction to a QMenu, QMenuBar, QActionGroup or QToolBar.

action = qt.ui.menu.add_action( menu|menubar|... , "text", [ "object_name" ] )

qt.ui.menu.new_action_group function  

The qt.ui.menu.new_action_group function creates a new QActionGroup and adds passed actions to it.

ag = qt.ui.menu.new_action_group( action, [ action, ... ] )

qt.ui.menu.new_action function  

The qt.ui.menu.new_action function creates a new QAction object with specifed parent.

action = qt.ui.menu.new_action( parent )

qt.ui.menu.new_menu function  

The qt.ui.menu.new_menu function creates a new QMenu object with specifed parent.

menu = qt.ui.menu.new_menu( parent )

qt.ui.menu.remove function  

The qt.ui.menu.remove function remove a QAction or QMenu from a QWidget or QActionGroup. The default is to remove from the parent QObject.

qt.ui.menu.remove( qaction|qmenu [, qwidget|qactiongroup ] )

Dialog functions  

qt.dialog.get_* family of functions  

These functions wrap various C++ static functions provided by Qt classes inheriting from the QDialog class. They are designed to request input from the user.

dirname = qt.dialog.get_existing_directory( [ "caption", "directory", QFileDialog::Option ] )
filename = qt.dialog.get_open_filename( [ "caption", "directory", "filter", QFileDialog::Option ] )
filename = qt.dialog.get_open_filenames( [ "caption", "directory", "filter", QFileDialog::Option ] )
filename = qt.dialog.get_save_filename( [ "caption", "directory", "filter", QFileDialog::Option ] )
color = qt.dialog.get_color( [ init_red, init_green, init_blue ] )
number = qt.dialog.get_double( [ "title", "label", value, min, max, decimals ] )
number = qt.dialog.get_integer( [ "title", "label", value, min, max, step ] )
text = qt.dialog.get_text( [ "title", "label", "init_text" ] )
string = qt.dialog.get_item( { "item", "item", ... }, [ "default_item", editable, "title", "label" ] )

qt.dialog.msg_* family of functions  

These functions wrap various C++ static functions provided by the QMessageBox class which open a pop-up message box.

qt.dialog.msg_about( "text" [ , "title" ] )
button = qt.dialog.msg_critical( "text" [ , "title", QMessageBox::StandardButtons,
QMessageBox::StandardButton ] )
button = qt.dialog.msg_information( "text" [ , "title", QMessageBox::StandardButtons,
QMessageBox::StandardButton ] )
button = qt.dialog.msg_question( "text" [ , "title", QMessageBox::StandardButtons,
QMessageBox::StandardButton ] )
button = qt.dialog.msg_warning( "text" [ , "title", QMessageBox::StandardButtons,
QMessageBox::StandardButton ] )

qt.dialog.*_view family of functions  

These functions open an ItemViewDialog dialog which expose lua tables to the user using either TableTreeModel or TableGridModel.

qt.dialog.tree_view( table [ , TableTreeModel::Attribute, "title" ] )
qt.dialog.table_view( table [ , TableTreeModel::Attribute, "title" ] )
qt.dialog.grid_view( table [ , TableGridModel::Attribute, "title", {column keys}, {row keys} ] )

Model/View functions  

qt.mvc.new_table_tree_model function  

This function returns a new TableTreeModel object which expose the specified lua table object. The new model can optionally be associated to some qt views.

model = qt.mvc.new_table_tree_model( table, TableTreeModel::Attributes, [ view_widget, ... ] )

qt.mvc.new_table_grid_model function  

This function returns a new TableGridModel object which expose the specified lua table object. The new model can optionally be associated to some qt views.

model = qt.mvc.new_table_grid_model( table, TableGridModel::Attributes, [ view_widget, ... ] )

qt.mvc.new_lua_model function  

This function returns a new LuaModel object. At least one lua function is expected as argument in order to implement a read only model. The new model can optionally be associated to some qt views.

model = qt.mvc.new_lua_model( get_fcn, [ set_fcn, ins_row_fcn, del_row_fnc,
ins_col_fcn, del_col_fcn, view_widget, ... ] )

qt.mvc.set_model function  

This function associates a model to one or more views.

qt.mvc.set_model( model, view_widget [, view_widget, ... ] )

qt.mvc.new_itemview_dialog function  

This function returns a new ItemViewDialog object. The model and view objects to use must be passed to this function.

dialog = qt.mvc.new_itemview_dialog( ItemViewDialog::EditActions, model, view )

See also qt.dialog.*_view family of functions section, qt.dialog.*_view family of functions section and qt.dialog.*_view family of functions section.

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 15:29:54 2013 using MkDoc