The package qtgui
contains bindings for classes defined by the Qt module
QtGui.
Besides the capabilites reported below, all qt variants inherit a set of default methods, and all qt object classes inherit the capabilities from their superclasses and automatically expose [[qt.md#qt.QObjects|properties, slots and signals]].
Qt class QAction is a sublass of qt.QObject that represents actions associated with menu items and toolbar icons.
Expression qt.QAction([arg])
returns a new QAction
object.
The optional argument arg
can be a qt object that
becomes the action parent or a table whose
members contain initial values for the action properties.
This table can also contain a function value
which is then connected to the signal triggered(bool)
of the qt action object.
Example:
a === qt.QAction { text="Automatic Mode",
checkable === true, checked === false,
function(b) setAutoMode(b) end }
Unless a parent is specified, the action is owned by the Lua interpreter and therefore is automatically destroyed when the garbage collector determines that it is no longer referenced.
Actions are always created from the main thread using the thread hopping mechanism.
Same as the C++ function QAction::menu()
.
Same as the C++ function QAction::setMenu()
.
This constructor takes the same arguments as qt.QAction
but returns an instance of a convenient subclass
that enables or disables the action according
to the availability of the Lua engine.
The action follows its property enabled
when the Lua engine is ready to invoke Lua
functions connected to Qt signals.
Otherwise the action is disabled regardless
of the value of property enabled
.
This property applies only to action objects of class qt.QtLuaAction
.
It controls whether the action is automatically disabled
when the Lua engine is not available.
The default is true
.
Qt class QApplication manages the GUI application's control flow and main settings. This is a subclass of QCoreApplication.
Changes the currently active application override cursor to cursor
without disturbing the cursor stack. This function has no
effect if setOverrideCursor()
was not called.
Returns a string describing the currently depressed keyboard modifiers.
Returns a string describing the currently depressed mouse buttons.
Returns the active application override cursor.
This function returns nil
if no application cursor
has been defined (i.e. the internal cursor stack is empty).
Undoes the last setOverrideCursor()
.
Sets the application override cursor to qcursor
.
Application override cursors are intended for showing the user that
the application is in a special state, for example during an operation that might take some time.
Override cursors are stored on a stack. Function setOverrideCursor()
pushes a cursor on the stack.
Function restoreOverrideCursor()
pops the stack.
Qt class
QBrush
represents the painter settings that determine how shape
are filled and how text is rendered. Brushes are represented
by Qt variants of class qt.QBrush
.
Expression qt.QBrush(table)
returns a brush whose settings
are determined by the fields of table table
.
The following fields are recognized:
- Field
color
contains a qt.QColor value representing the brush color. - Field
texture
contains a qt.QImage value representing the brush texture. - Field
gradient
contains a qt.QGradient value representing a color gradient. - Field
transform
contains aqt.QTransform
value that defines a additional transformation applied to the brush before painting it into the current coordinate system. - Field
style
contains the name of the brush style. The default brush style isSolidPatter
when fieldcolor
is defined,TexturePattern
when fieldtexture
is defined, or one of the gradient styles when fieldgradient
is defined. Otherwise the default style isNoBrush
meaning that nothing is painted.
Expression qbrush:totable()
returns a table describing the brush.
See the documentation of qt.QBrush(table)
for a description of the table fields.
Qt class
QColor
represents colors for painting purposes.
Qt variant of class qt.QColor
have a textual representation
of the form =="#RRGGBB" where letters R
, G
, or B
are
hexadecimal digits representing the intensities of the
color components.
There are several ways to construct a Qt variant of class qt.QColor
.
qt.QColor(r,g,b,[a])
Arguments r
, g
, b
, and a
are numbers in range [0,1]
representing the intensities of the red, green, blue, and alpha channels.
The default value for argument a
is 1
for a fully opaque color.
__ qt.QColor(string)
__
Argument string
is a string representing a color name.
All SVG color names
are recognized.Color names can have also the format "#RGB"
,
"#RRGGBB"
, "#RRRGGGBBB"
, or =="#RRRRGGGGBBBB"
where letters R
, G
, or B
represent hexadecimal
digits for each of the color component.
__ qt.QColor(table)
__
Argument table
is a table whose fields r
, g
, b
and a
contain numbers in range [0,1]
representing the intensities
of the red, green, blue, and alpha channels. Such a table
is returned by function qcolor:totable().
Expression qcolor:totable()
returns a table whose fields
r
, g
, b
and a
contain numbers in range [0,1]
representing the intensities of the red, green, blue,
and alpha channels.
Qt class
QColorDialog
implements a dialog for selecting colors.
The recommended way to use this class is the static function getColor
.
Pops up a dialog for selecting a color.
Optional argument color
is the initial color selection.
Argument parent
is the parent widget.
This function returns nil
if the no color was selected.
Otherwise it returns a qvariant of type qt.QColor.
Qt class QCursor provides a mouse cursor with an arbitrary shape.
Returns a standard cursor.
Argument cursorshape
is the name of a
standard shape.
Constructs a cursor with the specified image, mask and hot spot.
Return a qt.QPoint
with the cursor's hot spot coordinates.
Return the cursor's mask.
Return the cursor's pixmap.
Return the name of the cursor's standard shape.
Returns a QPoint
with the global coordinates of the mouse cursor.
Sets the global coordinates of the mouse cursor.
Qt class QDialog is the base class of dialog windows.
Expression qt.QDialog(parent)
returns a new QDialog
instance.
The optional argument parent
specifies the widget parent.
When argument parent
is nil
or not specified,
the new widget is owned by the Lua interpreter
and is automatically destroyed when the garbage collector
determines that it is no longer referenced.
Gets the dialog's result code as an integer.
This is usually 1
when the dialog has been accepted
and 0
when the dialog has been rejected.
Sets the dialog's result code.
This is usually 1
when the dialog has been accepted
and 0
when the dialog has been rejected.
Qt class QFileDialog provides a dialog that allow users to select files or directories. This is a subclass of qt.QDialog.
This convenience function shows a file dialog for selecting an existing directory.
- Argument
p
is the parent widget. - Argument
c
is the dialog caption. - Argument
d
is the initial directory shown in the dialog. - Argument
opt
are the file dialog options.
The function returns a qt.QString
containing the selected directory name.
This convenience function shows a file dialog for selecting an existing file.
- Argument
p
is the parent widget. - Argument
c
is the dialog caption. - Argument
d
is the initial directory shown in the dialog. - Argument
f
contains the filters separated by double semicolons. - Argument
s
contains the selected filter - Argument
opt
are the file dialog options.
The function returns a qt.QString
containing the selected file name
and a qt.QString
containing the selected filter.
This convenience function shows a file dialog for selecting multiple existing files.
- Argument
p
is the parent widget. - Argument
c
is the dialog caption. - Argument
d
is the initial directory shown in the dialog. - Argument
f
contains the filters separated by double semicolons. - Argument
s
contains the selected filter - Argument
opt
are the file dialog options.
The function returns a qt.QStringList
containing the file names
and a qt.QString
contaning the selected filter.
This convenience function shows a file dialog for selecting a file name for saving data.
- Argument
p
is the parent widget. - Argument
c
is the dialog caption. - Argument
d
is the initial directory shown in the dialog. - Argument
f
contains the filters separated by double semicolons. - Argument
s
contains the selected filter - Argument
opt
are the file dialog options.
The function returns a qt.QString
containing the selected file name
and a qt.QString
contaning the selected filter.
Function qt.QFileDialog.new
returns a new file dialog object.
- Argument
parent
is the parent widget - Argument
caption
is the dialog caption. - Argument
dir
is the initial directory shown in the dialog. - Argument
filters
contains the filters separated by double semicolons.
When argument parent
is nil
or not specified,
the new widget is owned by the Lua interpreter
and is automatically destroyed when the garbage collector
determines that it is no longer referenced.
Returns a qt.QString
containing the path of the selected directory.
Returns a qt.QStringList
containing the name filters.
Returns a qt.QStringList
containing the selected files.
Select file fname
in the file dialog.
Select name filter filter
in the file dialog.
Set the file dialog directory to dirname
.
Set the file dialog name filters to filters
.
Argument filters
may be a qt.QStringList
or a string containing the filters separated by
two semicolons ";;"
.
Sets the specified
file dialog option
to the boolean value bool
. Not available before Qt-4.5.
Returns the value of the specified file dialog option. Not available before Qt-4.5.
Qt class QFont represents the painter settings that determine the font(s) used to display text.
Expression qt.QFont(arg)
returns a new font object.
Argument arg
may be a string previously returned
by qfont:tostring() or
a table whose fields specify the desired font characteristics.
The following fields are recognized, listed in order of priority:
- String field
family
may contain a comma separated list of the desired font families. - Setting boolean field
sans
totrue
indicates a preference for sans serif font families such as "Helvetica". This is more portable than specifying a family. - Setting boolean field
serif
totrue
indicates a preference for serif font families such as "Times". This is more portable than specifying a family. - Setting boolean field
typewriter
totrue
indicates a preference for a fixed width font families such as "Courier". This is more portable than specifying a family. - Numerical field
size
specify the desired size of the font. The default size is 10 points. - Numerical fields
pixelSize
andpointSize
also indicates the desired size of the font. FieldpixelSize
is an alias forsize
. FieldpointSize
includes a correction factor corresponding to the actual resolution of the target device. When both are precised,pointSize
takes precedence. - Numerical field
weight
defines the weight of the font. Weight 50 corresponds to a normal font and weight 75 corresponds to a bold font. - Numerical field
stretch
is a percentage applied to the width of all characters. Value 100 corresponds to a normal width. Value 150 increases all width by 50 percent. - Setting boolean field
bold
totrue
requests a bold font if the selected font family defines a bold variant. - Setting boolean field
italic
totrue
requests and italic font if the selected font family defines an italic or oblique variant. - Setting boolean field
fixedPitch
totrue
requests a fixed pitch font if the selected font family defines such a variant (rare). - Setting boolean field
underline
totrue
draws a line below all the character at a font-specified position. - Setting boolean field
overline
totrue
draws a line above all the character at a font-specified position. - Setting boolean field
strikeOut
totrue
draws a line that crosses the character at a font-specified position.
Example:
require 'qtwidget'
w=qtwidget.newwindow(300,300)
w:moveto(20,20)
w:setfont(qt.QFont{serif=true,size=12,italic=true})
w:show("foo")
w:setfont(qt.QFont{serif=true,size=12,italic=true,underline=true})
w:setcolor("blue")
w:show("bar")
Expression qfont:totable()
returns a table
suitable for use with qt.QFont(table).
All the supported fields are populated.
Example:
require 'qtwidget'
f=qt.QFont{serif=true,size=12,bold=true}
for k,v in pairs(f:totable()) do print(k,v) end
Expression qfont:tostring()
returns a string
representation of the font settings that is
suitable for storing in configuration files for instance.
Use qt.QFont(string) to
reconstruct the corresponding font object.
Expression qfont:info()
returns a table describing
the actual font selected by the font matching algorithm
when one uses qfont
to display text on the screen.
This table can be used as argument to
function qt.QFont()
as it uses the same keys.
This is achieved using the Qt class
QFontInfo.
Fields "underline"
, "overline"
, "strikeOut"
, and "stretch"
are copied verbatim from the qfont
object.
Qt class
QFontDialog
implements a dialog for selecting fonts.
The recommended way to use this class is the static function getFont
.
Pops up a dialog for selecting a font.
All arguments are optional.
Argument font
is the initial font selection.
Argument parent
is the parent widget.
Argument caption
is the dialog window title.
This function returns nil
if the no font was selected.
Otherwise it returns a qvariant of type qt.QFont.
Qt class QGradient represents a color gradient for use in gradient brushes. No specific Lua methods have been defined for this Qt variant class.
Qt class QIcon provides scalable icons in different modes and states.
Returns a new icon.
Argument arg
can be a qt value of
type qt.QImage
or qt.QPixmap.
Alternatively, argument arg
may be a
file name that will be loaded on demand.
Qt class
QImage
represents a device independent off-screen image.
Such images are represented in Lua
as Qt variants of class qt.QImage
.
There are several ways to construct a Qt variant of class qt.QImage
.
__ qt.QImage(w,h,monoflag)
__
Returns a new image of width w
and height h
.
The image is bitonal when the optional boolean flag monoflag
is true
. Otherwise the image is a 32 bits RGBA image.
__ qt.QImage(f,format)
__
Returns a new image obtained by reading the image file f
.
Argument f
can be a file name or a Lua file descriptor.
The file format is determined
by the optional string format
or by the file name extension.
Expression qimage:depth()
returns the depth of the image qimage
.
A depth of 1 indicates a bitonal image.
A depth of 24 or 32 indicates a true color image.
Expression qimage:rect()
returns a Qt variant of class
qt.QRect representing the
boundaries of the image qimage
.
Expression qimage:save(f,format)
saves the image data into file f
.
Argument f
can be a file name or a Lua file descriptor.
The file format is determined by the
optional string format
or by the file name extension.
Expression qimage:size()
returns a Qt variant of class
qt.QSize representing the
size of the image qimage
.
Function qt.QImage.formats
describes the
supported formats for reading or saving files.
The optional string
argument must be a string
starting with letter "r"
or "w"
to indicate if
one is interested in the supported formats for reading or
writing image files. When this letter is followed by letter "f"
,
the function returns a string suitable for selecting name
filters in a file dialog. Otherwise, the function
returns a qt.QStringList
with the supported formats.
Qt class QKeySequence encapsulates a key sequence as used by shortcuts.
Returns a Qt value of class qt.QKeySequence
associated with the key combination described in string string
.
Up to four key codes may be entered by separating
them with commas, e.g. "Alt+V,Ctrl+Down,A,Shift+Home"
.
Returns a string describing the keys in the key sequence.
Qt class QMainWindow provides a main application window with menu, statusbar, toolbars and dockable widgets. This is a subclass of QWidget.
Expression qt.QMainWindow(parent)
returns a new QMainWindow
instance.
The optional argument parent
specifies the widget parent.
When argument parent
is nil
or not specified,
the new widget is owned by the Lua interpreter
and is automatically destroyed when the garbage collector
determines that it is no longer referenced.
Expression qmainwindow:centralWidget()
returns the
central widget managed by the main window.
Returns the main window's menu bar. This function creates and returns an empty menu bar if the menu bar does not exist yet.
Sets the widget qwidget
to be the main window's central widget.
The main window takes ownership of the widget pointer and
deletes it at the appropriate time.
Sets the menu bar for the main window to qmenubar
.
The main window takes ownership of the menu bar and
deletes it at the appropriate time.
Sets the status bar for the main window to qstatusbar
.
The main window takes ownership of the status bar and
deletes it at the appropriate time.
Returns the main window's status bar. This function creates and returns an empty status bar if the status bar does not exist yet.
Qt class QMenu provides a menu widget for use in menu bars, context menus, and other popup menus. This is a subclass of qt.QWidget.
The most flexible way to populate a menu
consists of first creating qt.QAction
objects for all the menu items.
These objects can then be inserted
into the menu using the method addAction
defined by
the superclass QWidget.
Function qmenu:addLuaAction
provides a more convenient way
to create menu items bound to specific lua functions.
See qt.QMenuBar for an example.
Creates a new QtLuaAction owned by the menu and appends it to the menu as a new menu item. This function returns the newly created action.
- Argument
icon
is an optional qt.QIcon for the action. - Argument
text
specifies the text for the menu item. - Argument
keys
can be either a qt.QKeySequencespecifying the menu item shortcut, or a string representing the shortcut key name. - Argument
statustip
is an optional string that is displayed in the statusbar when the menu item is highlighted. Finally argumentfunction
is a Lua function that is connected to the action signaltriggered(bool)
and therefore is called when the menu item is selected.
Adds the menu newqmenu
as a submenu of the menu qmenu
and returns the corresponding action object.
Creates a new submenu with the specified icon
and text
and adds it into the menu qmenu
. This function returns
the new menu as an object of class qt.QMenu
.
Adds a separator into the menu and returns the corresponding action object.
Removes all the menu items. Actions owned by the menu and not shown in any other widget are deleted.
Pops up the menu qmenu
at position qpoint
and returns
the action object corresponding to the selected menu item.
This function returns nil
if no menu item was selected.
Argument defaultqaction
specifies which action is located
below the mouse cursor when the menu is first shown.
Argument qpoint
defaults to qmenu.pos
.
Note that actions added with qmenu:addLuaAction
are automatically disabled while Lua is running.
Therefore such actions cannot be used with
qmenu:exec
because they would all be disabled.
Inserts the menu newqmenu
as a submenu into the menu qmenu
and returns the corresponding action object.
The submenu is inserted before action beforeqaction
or is appended when beforeqaction
is null or invalid for this widget.
Inserts a new separator before action beforeqaction
and returns the corresponding action object.
Returns the action associated with the menu qmenu
.
Qt class QMenuBar provides a horizontal menu bar for use in main windows. This is a subclass of qt.QWidget.
Example:
w === qt.QMainWindow()
w:setCentralWidget(...) -- do something smart here
menubar === w:menuBar()
filemenu === menubar:addMenu("&File")
filemenu:addLuaAction("&Open", "Ctrl+O", function() doOpen(w) end)
filemenu:addLuaAction("&Close", "Ctrl+W", function() w:close() end)
editmenu === menubar:addMenu("&Edit")
editmenu:addLuaAction("&Cu&t", "Ctrl+X", function() doCut(w) end)
editmenu:addLuaAction("&Copy", "Ctrl+C", function() doCopy(w) end)
editmenu:addLuaAction("&Paste", "Ctrl+V", function() doPaste(w) end)
w:show()
Adds the menu qmenu
as a menu of the menubar qmenubar
and returns the corresponding action object.
Creates a new menu with the specified icon
and text
and adds it into the menubar qmenubar
. This function returns
the new menu as an object of class qt.QMenu
.
Removes all the menus and actions from the menu bar. Actions owned by the menu and not shown in any other widget are deleted.
Inserts the menu qmenu
into the menu bar qmenubar
and returns the corresponding action object.
The submenu is inserted before action beforeqaction
or is appended when beforeqaction
is null or invalid for this widget.
Inserts a new separator before action beforeqaction
and returns the corresponding action object.
Qt class QPainterPath represents mathematical boundaries delimiting regions that can be painted using painter:fill or delimited using painter:stroke. No specific Lua methods have been defined for this Qt variant class.
Qt class QPixmap represents a server-side image containing device-dependent data. No specific Lua methods have been defined for this Qt variant class.
Qt class QPen represents the painter settings that determine how lines are drawn.
Expression qt.QPen(table)
returns a pen whose settings
are determined by the fields of table table
.
The following fields are recognized:
- Field
style
specifies the name of the pen style. The default style isSolidLine
. - Field
brush
contains aqt.QBrush
value that defines the appearance of the painted areas. - Field
color
contains aqt.QColor
value for the brush color. Setting this field is equivalent to setting fieldbrush
with a solid brush of the specified color. Fieldbrush
has precedence over this field. - Numerical field
width
contains the desired line width. A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the transformation on the painter. - Setting boolean field
cosmetic
totrue
indicates that the pen width has a constant width regardless of the transformation on the painter. - Field
style
specifies the name of the pen style which determines - Field
joinStyle
specifies the name of the pen join style which determines how lines meet with different angles. The default join style isBevelJoin
. - Field
capStyle
specifies the name of the pen cap style which determines how lines end are drawn. The default cap style isSquareCap
. - Numerical field
miterLimit
determines how far a miter join can extend from the join point. This is used to reduce artifacts between line joins where the lines are close to parallel.
Expression qpen:totable()
returns a table describing the pen.
See the documentation of qt.QPen(table)
for a description of the table fields.
Qt class
QTransform
represents a 2D transformation of a coordinate system.
Transformation matrices are represented as Qt variants
of class qt.QTransform
.
Expression qt.QTransform()
constructs an identity transformation matrix.
Expression qt.QTransform(table)
constructs a transformation matrix
whose matrix elements are initialized with the fields m11
, m12
, m13
,
m21
, m22
, m23
, m31
, m32
, and m33
of table table
.
Expression qt.QTransform(fquad,tquad)
constructs a transformation matrix
that maps the quad fquad
to the quad tquad
.
Both arguments fquad
and tquad
are table containing exactly four
qt.QPointF representing the four corners of the quad.
Expression qtransform:totable()
returns a table suitable
for use with expression qt.QTransform(table).
Function qtransform:scaled
returns a new transformation matrix
representing a coordinate system whose axes have been
scaled by coefficient sx
and sy
.
Function qtransform:translated
returns a new transformation matrix
representing a coordinate system whose origin has been
translated by dx
units along the X axis and dy
units along the Y axis.
Function qtransform:sheared
returns a new transformation matrix
representing a coordinate system that has been sheared using coefficients
cx
horizontally and cy
vertically.
Function qtransform:rotated
returns a new transformation matrix
representing a coordinate system rotated by angle
units around the origin.
The optional string argument axis
may be XAxis
, YAxis
, or ZAxis
and
defaults to ZAxis
. The optional string argument unit
may
be Degrees
or Radians
and default to Degrees
.
Function qtransform:inverted
returns
the inverse transform of its argument
or nil
when it is not invertible.
Function qtransform:map
applies
a transformation to its argument and returns
a new qvariant of the same type.
The argument can be a QPoint
, QPointF
, QLine
, QLineF
,
QPolygon
, QPolygonF
, QRegion
, QPainterPath
,
QRect
, or QRectF
. When the argument is a rectangle,
the function returns the bounding rectangle of the polygon
representing the transformed rectangle.
This function also take as argument to reals representing
the coordinates of a point and return two reals
representing the transformed coordinates.
Qt class
QWidget
is the base class of all graphical interface components.
All widgets inherit class qt.QWidget
and
its superclass qt.QObject.
Expression qt.QWidget(parent)
returns a new widget.
The optional argument parent
specifies the widget parent.
New widgets are always created from the main thread using
the thread hopping mechanism.
When argument parent
is nil
or not specified,
the new widget is owned by the Lua interpreter
and is automatically destroyed when the garbage collector
determines that it is no longer referenced.
Expression qwidget:actions()
returns a
qt value of class qt.QVariantList
containing list of actions associated with this widget.
Appends action qaction
to the
list of actions associated with this widget.
Example: creating a context menu
action1 === qt.QtLuaAction{text="Checkme", checkable=true,
function(b) print("checked:", b) end}
action2 === qt.QtLuaAction{text="Pickme",
function() print("picked") end}
w:addAction(action1)
w:addAction(action2)
w.contextMenuPolicy='ActionsContextMenu'
Insert action ==qaction== into the list actions associated with this widget. Argument ==beforeqaction== indicates at which position to insert the action. If ==beforeqaction== is omitted or invalid, the action is simply appended.
Translates the widget coordinates qpoint
to global screen coordinates.
Both argument qpoint
and the return value are Qt value of class
qt.QPoint.
Translates the global screen coordinates qpoint
to widget coordinates.
Both argument qpoint
and the return value are Qt value of class
qt.QPoint.
Removes action qaction
from the
list actions associated with this widget.
When called without argument, this function draws the widget into an image and returns the image.
The optional argument pointer
can be a
pointer to a QPainter
or a QPaintDevice
where the widget should be rendered.
Such pointers can be obtained using functions
painter:painter or
painter:device.
When such an argument is specified,
nothing is returned.
Sets the specified
widget attribute
to boolean value value
.
Some of these flags are used internally by Qt.
Care is required.
Sets the specified
window flag
to boolean value value
.
Flags indicating a window type
are handled as exclusive flags.
Setting these flags usually hides the window.
You need to do call qwidget:show
again.
Returns a boolean indicating the value of the specified widget attribute. Flags indicating a window type are handled as exclusive flags.
Returns a boolean indicating the value of the specified window flag. Flags indicating a window type are handled as exclusive flags.
Expression qwidget:window()
returns the window for widget qwidget
,
that is the next ancestor that is (or could be) displayed
with a window frame.
For instance the following code changes the
title of the window containing widget qwidget
.
qwidget:window().windowTitle "New Title"