Welcome to mirror list, hosted at ThFree Co, Russian Federation.

qtgui.md « doc - github.com/torch/qtlua.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9985c940de68ac85ff4b9aad1ec54e524c9c330f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
<a name="qtgui.dok"></a>
# QtGui Bindings #

The package `qtgui` 
contains bindings for classes defined by the Qt module
[QtGui](http://doc.trolltech.com/4.4/qtcore.html).

Besides the capabilites reported below, all qt variants inherit a set
of [default methods](qt.md#qt.QVariants), and all qt object
classes inherit the capabilities from their superclasses and
automatically expose [[qt.md#qt.QObjects|properties, slots and
signals]].


<a name="qaction"></a>
## qt.QAction, qt.QtLuaAction ##
<a name="qtluaaction"></a>

Qt class 
[QAction](http://doc.trolltech.com/4.4/qaction.html) 
is a sublass of [qt.QObject](qtcore.md#qt.qobject)
that represents actions associated with menu items
and toolbar icons.  


<a name="qaction"></a>
### qt.QAction([arg]) ###

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:
```lua
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](qt.md#qt.qcall) mechanism.

<a name="qaction.menu"></a>
### qaction:menu() ###

Same as the C++ function `QAction::menu()`.

<a name="qaction.setmenu"></a>
### qaction:setMenu() ###


Same as the C++ function `QAction::setMenu()`.

<a name="qtluaaction"></a>
### qt.QtLuaAction([arg]) ###

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`.

<a name="qtluaaction.autodisable"></a>
### qtluaaction.autoDisable ###

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`.


<a name="qapplication"></a>
## qt.QApplication ##

Qt class [QApplication](http://doc.trolltech.com/4.4/qapplication.html)
manages the GUI application's control flow and main settings. This is a 
subclass of [QCoreApplication](qtcore.md#qcoreapplication).

<a name="qapplication.changeOverrideCursor"></a>
### qt.QApplication.changeOverrideCursor(qcursor) ###

Changes the currently active application override cursor to cursor
without disturbing the cursor stack. This function has no 
effect if `setOverrideCursor()` was not called.

<a name="qapplication.keyboardModifiers"></a>
### qt.QApplication.keyboardModifiers() ###

Returns a string describing the currently depressed keyboard modifiers.

<a name="qapplication.mouseButtons"></a>
### qt.QApplication.mouseButtons() ###

Returns a string describing the currently depressed mouse buttons.

<a name="qapplication.overrideCursor"></a>
### qt.QApplication.overrideCursor() ###

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).

<a name="qapplication.restoreOverrideCursor"></a>
### qt.QApplication.restoreOverrideCursor() ###

Undoes the last `setOverrideCursor()`.

<a name="qapplication.setoverridecursor"></a>
### qt.QApplication.setOverrideCursor(qcursor) ###

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.


<a name="qbrush"></a>
## qt.QBrush ##

Qt class 
[QBrush](http://doc.trolltech.com/4.4/qbrush.html) 
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`.


<a name="qbrush"></a>
### qt.QBrush(table) ###
<a name="qbrushfromtable"></a>

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](#qcolor) value representing the brush color. 
  * Field `texture` contains a [qt.QImage](#qimage) value representing the brush texture.
  * Field `gradient` contains a [qt.QGradient](#qgradient) value representing a color gradient.
  * Field `transform` contains a `qt.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](http://doc.trolltech.com/4.4/qt.html#BrushStyle-enum). The default brush style is `SolidPatter` when field `color` is defined, `TexturePattern` when field `texture` is defined, or one of the gradient styles when field `gradient` is defined.  Otherwise the default style is `NoBrush` meaning that nothing is painted.


<a name="qbrush.totable"></a>
### qbrush:totable() ###

Expression `qbrush:totable()` returns a table describing the brush.
See the documentation of [qt.QBrush(table)](#qbrushfromtable)
for a description of the table fields.


<a name="qcolor"></a>
## qt.QColor ##

Qt class 
[QColor](http://doc.trolltech.com/4.4/qcolor.html) 
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.


<a name="qcolor"></a>
### qt.QColor(...) ###

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](http://www.w3.org/TR/SVG/types.html#ColorKeywords)
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()](#qcolortotable).

<a name="qcolor.totable"></a>
### qcolor:totable() ###
<a name="qcolortotable"></a>

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.


<a name="qcolordialog"></a>
## qt.QColorDialog ##

Qt class
[QColorDialog](http://doc.trolltech.com/4.4/qcolordialog.html) 
implements a dialog for selecting colors.  
The recommended way to use this class is the static function `getColor`.

<a name="qcolordialog.getcolor"></a>
### qt.QColorDialog.getColor([font],[parent]) ###

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](#qcolor).

<a name="qcursor"></a>
## qt.QCursor ##

Qt class 
[QCursor](http://doc.trolltech.com/4.4/qcursor.html) 
provides a mouse cursor with an arbitrary shape.

<a name="qcursor"></a>
### qt.QCursor(cursorshape) ###

Returns a standard cursor.
Argument `cursorshape` is the name of a 
[standard shape](http://doc.trolltech.com/4.4/qt.html#CursorShape-enum).

<a name="qcursor"></a>
### qt.QCursor(image,[mask],[posx,[posy]) ###

Constructs a cursor with the specified image, mask and hot spot.

<a name="qcursor.hotSpot"></a>
### qcursor:hotSpot() ###

Return a `qt.QPoint` with the cursor's hot spot coordinates.

<a name="qcursor.mask"></a>
### qcursor:mask() ###

Return the cursor's mask.

<a name="qcursor.pixmap"></a>
### qcursor:pixmap() ###

Return the cursor's pixmap.

<a name="qcursor.shape"></a>
### qcursor:shape() ###

Return the name of the cursor's
[standard shape](http://doc.trolltech.com/4.4/qt.html#CursorShape-enum).

<a name="qcursor.pos"></a>
### qt.QCursor.pos() ###

Returns a `QPoint` with the global coordinates of the mouse cursor.

<a name="qcursor.setPos"></a>
### qt.QCursor.setPos(qpoint) ###

Sets the global coordinates of the mouse cursor.

<a name="qdialog"></a>
## qt.QDialog ##

Qt class 
[QDialog](http://doc.trolltech.com/4.4/qdialog.html) 
is the base class of dialog windows.

<a name="qdialog"></a>
### qt.QDialog([parent]) ###

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.

<a name="qdialog.result"></a>
### qdialog:result() ###

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.

<a name="qdialog.setresult"></a>
### qdialog:setResult(integer) ###

Sets the dialog's result code.
This is usually `1` when the dialog has been accepted
and `0` when the dialog has been rejected.


<a name="qfiledialog"></a>
## qt.QFileDialog ##

Qt class 
[QFileDialog](http://doc.trolltech.com/4.4/qfiledialog.html) 
provides a dialog that allow users to select files or directories. 
This is a subclass of [qt.QDialog](#qdialog).

<a name="qfiledialog.getExistingDirectory"></a>
### qt.QFileDialog.getExistingDirectory([p.[c,[d,[opt]]]]) ###

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](http://doc.trolltech.com/4.4/qfiledialog.html#Option-enum).

The function returns a `qt.QString` containing the selected directory name.

<a name="qfiledialog.getOpenFileName"></a>
### qt.QFileDialog.getOpenFileName([p,[c,[d,[f,[s,[opt]]]]]]) ###

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](http://doc.trolltech.com/4.4/qfiledialog.html#Option-enum).

The function returns a `qt.QString` containing the selected file name
and a `qt.QString` contaning the selected filter.

<a name="qfiledialog.getOpenFileNames"></a>
### qt.QFileDialog.getOpenFileNames([p,[c,[d,[f,[s,[opt]]]]]]) ###

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](http://doc.trolltech.com/4.4/qfiledialog.html#Option-enum).

The function returns a `qt.QStringList` containing the file names
and a `qt.QString` contaning the selected filter.

<a name="qfiledialog.getsavefilename"></a>
### qt.QFileDialog.getSaveFileName([p,[c,[d,[f,[s,[opt]]]]]]) ###

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](http://doc.trolltech.com/4.4/qfiledialog.html#Option-enum).

The function returns a `qt.QString` containing the selected file name
and a `qt.QString` contaning the selected filter.

<a name="qfiledialog.new"></a>
### qt.QFileDialog.new([parent.[caption,[dir,[filters]]]]) ###

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.

<a name="qfiledialog.directory"></a>
### qfiledialog:directory() ###

Returns a `qt.QString` containing the path of the selected directory.

<a name="qfiledialog.nameFilters"></a>
### qfiledialog:nameFilters() ###

Returns a `qt.QStringList` containing the name filters.

<a name="qfiledialog.selectedFiles"></a>
### qfiledialog:selectedFiles() ###

Returns a `qt.QStringList` containing the selected files.

<a name="qfiledialog.selectFile"></a>
### qfiledialog:selectFile(fname) ###

Select file `fname` in the file dialog.

<a name="qfiledialog.selectNameFilter"></a>
### qfiledialog:selectNameFilter(filter) ###

Select name filter `filter` in the file dialog.

<a name="qfiledialog.setDirectory"></a>
### qfiledialog:setDirectory(dirname) ###

Set the file dialog directory to `dirname`.

<a name="qfiledialog.setNameFilters"></a>
### qfiledialog:setNameFilters(filters) ###

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 `";;"`.

<a name="qfiledialog.setOption"></a>
### qfiledialog:setOption(option, bool) ###

Sets the specified
[file dialog option](http://doc.trolltech.com/4.5/qfiledialog.html#Option-enum)
to the boolean value `bool`.  Not available before Qt-4.5.

### qfiledialog:testOption(option) ###

Returns the value of the specified
[file dialog option](http://doc.trolltech.com/4.5/qfiledialog.html#Option-enum).
Not available before Qt-4.5.

<a name="qfont"></a>
## qt.QFont ##

Qt class 
[QFont](http://doc.trolltech.com/4.4/qfont.html) 
represents the painter settings that determine the font(s)
used to display text. 


<a name="qfont"></a>
### qt.QFont(arg) ###
<a name="qfontfromtable"></a>

Expression `qt.QFont(arg)` returns a new font object.
Argument `arg` may be a string previously returned
by [qfont:tostring()](#qfonttostring) 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` to `true` indicates a preference for sans serif font families such as "Helvetica". This is more portable than specifying a family.
  * Setting boolean field `serif` to `true` indicates a preference for serif font families such as "Times". This is more portable than specifying a family.
  * Setting boolean field `typewriter` to `true` 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` and `pointSize` also indicates the desired size of the font. Field `pixelSize` is an alias for `size`. Field `pointSize` 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` to `true` requests a bold font if the selected font family defines a bold variant.
  * Setting boolean field `italic` to `true` requests and italic font if the selected font family defines an italic or oblique variant.
  * Setting boolean field `fixedPitch` to `true` requests a fixed pitch font if the selected font family defines such a variant (rare).
  * Setting boolean field `underline` to `true` draws a line below all the character at a font-specified position.
  * Setting boolean field `overline` to `true` draws a line above all the character at a font-specified position.
  * Setting boolean field `strikeOut` to `true` draws a line that crosses the character at a font-specified position.

Example:
```lua
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")
```


<a name="qfont.totable"></a>
### qfont:totable() ###

Expression `qfont:totable()` returns a table
suitable for use with [qt.QFont(table)](#qfontfromtable).
All the supported fields are populated.

Example:
```lua
require 'qtwidget'
f=qt.QFont{serif=true,size=12,bold=true}
for k,v in pairs(f:totable()) do print(k,v) end 
```

<a name="qfonttostring"></a>
### qfont:tostring() ###
<a name="qfont.tostring"></a>

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)](#qfontfromtable) to
reconstruct the corresponding font object.

<a name="qfontinfo"></a>
### qfont:info() ###
<a name="qfont.info"></a>

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()](#qfontfromtable)
as it uses the same keys.  
This is achieved using the Qt class
[QFontInfo](http://doc.trolltech.com/4.4/qfontinfo.html).
Fields `"underline"`, `"overline"`, `"strikeOut"`, and `"stretch"` 
are copied verbatim from the `qfont` object.

<a name="qfontdialog"></a>
## qt.QFontDialog ##

Qt class
[QFontDialog](http://doc.trolltech.com/4.4/qfontdialog.html) 
implements a dialog for selecting fonts.  
The recommended way to use this class is the static function `getFont`.

<a name="qfontdialog.getfont"></a>
### qt.QFontDialog.getFont([font],[parent, [caption]]) ###

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](#qfont).


<a name="qgradient"></a>
## qt.QGradient ##

Qt class 
[QGradient](http://doc.trolltech.com/4.4/qgradient.html) 
represents a color gradient for use in [gradient brushes](#qbrush).
No specific Lua methods have been defined for this Qt variant class.


<a name="qicon"></a>
## qt.QIcon ##

Qt class 
[QIcon](http://doc.trolltech.com/4.4/qimage.html) 
provides scalable icons in different modes and states.

<a name="qicon"></a>
### qt.QIcon([arg]) ###

Returns a new icon.
Argument `arg` can be a qt value of 
type [qt.QImage](#qimage)
or [qt.QPixmap](#qpixmap).
Alternatively, argument `arg` may be a
file name that will be loaded on demand.


<a name="qimage"></a>
## qt.QImage ##

Qt class 
[QImage](http://doc.trolltech.com/4.4/qimage.html) 
represents a device independent off-screen image.
Such images are represented in Lua 
as Qt variants of class `qt.QImage`.

<a name="qimage"></a>
### 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](#qimageformats) is determined 
by the optional string `format` or by the file name extension.


<a name="qimage.depth"></a>
### qimage:depth() ###

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.

<a name="qimage.rect"></a>
### qimage:rect() ###

Expression `qimage:rect()` returns a Qt variant of class
[qt.QRect](qtcore.md#qrect) representing the
boundaries of the image `qimage`.

<a name="qimage.save"></a>
### qimage:save(f,[format]) ###

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](#qimageformats) is determined by the 
optional string `format` or by the file name extension.

<a name="qimage.size"></a>
### qimage:size() ###

Expression `qimage:size()` returns a Qt variant of class
[qt.QSize](qtcore.md#qsize) representing the
size of the image `qimage`.

<a name="qimage.formats"></a>
### qt.QImage.formats([string]) ###
<a name="qimageformats"></a>

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.



<a name="qkeysequence"></a>
## qt.QKeySequence ##

Qt class
[QKeySequence](http://doc.trolltech.com/4.4/qkeysequence.html) 
encapsulates a key sequence as used by shortcuts.

<a name="qkeysequence"></a>
### qt.QKeySequence(string) ###

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"`.

<a name="qkeysequence.tostring"></a>
### qkeysequence:tostring() ###

Returns a string describing the keys in the key sequence.


<a name="qmainwindow"></a>
## qt.QMainWindow ##

Qt class 
[QMainWindow](http://doc.trolltech.com/4.4/qmainwindow.html) 
provides a main application window with menu, statusbar, toolbars
and dockable widgets. This is a subclass of [QWidget](#qwidget).

<a name="qmainwindow"></a>
### qt.QMainWindow([parent]) ###

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.

<a name="qmainwindow.centralWidget"></a>
### qmainwindow:centralWidget() ###

Expression `qmainwindow:centralWidget()` returns the
central widget managed by the main window.

<a name="qmainwindow.menuBar"></a>
### qmainwindow:menuBar() ###

Returns the main window's menu bar.
This function creates and returns an empty menu bar
if the menu bar does not exist yet.

<a name="qmainwindow.setcentralwidget"></a>
### qmainwindow:setCentralWidget(qwidget) ###

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.

<a name="qmainwindow.setmenubar"></a>
### qmainwindow:setMenuBar(qmenubar) ###

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.

<a name="qmainwindow.setstatusbar"></a>
### qmainwindow:setStatusBar(qstatusbar) ###

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.

<a name="qmainwindow.statusBar"></a>
### qmainwindow:statusBar() ###

Returns the main window's status bar.
This function creates and returns an empty status bar
if the status bar does not exist yet.


<a name="qmenu"></a>
## qt.QMenu ##

Qt class 
[QMenu](http://doc.trolltech.com/4.4/qmenu.html) 
provides a menu widget for use in menu bars, 
context menus, and other popup menus. 
This is a subclass of [qt.QWidget](#qwidget).

The most flexible way to populate a menu
consists of first creating [qt.QAction](#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](#qwidget).  

Function `qmenu:addLuaAction` provides a more convenient way 
to create menu items bound to specific lua functions.
See [qt.QMenuBar](#qmenubar) for an example.

<a name="qmenu.addLuaAction"></a>
### qmenu:addLuaAction([icon,]text[,keys[,statustip]][,function]) ###

Creates a new [QtLuaAction](#qaction) 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](#qicon) for the action.
  * Argument `text` specifies the text for the menu item.
  * Argument `keys` can be either a [qt.QKeySequence](#qkeysequence)specifying 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 argument `function` is a Lua function that is 
connected to the action signal `triggered(bool)` and
therefore is called when the menu item is selected. 

<a name="qmenu.addMenu"></a>
### qmenu:addMenu(newqmenu) ###

Adds the menu `newqmenu` as a submenu of the menu `qmenu`
and returns the corresponding action object.

<a name="qmenu.addMenu"></a>
### qmenu:addMenu([icon,] text) ###

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`.

<a name="qmenu.addSeparator"></a>
### qmenu:addSeparator() ###

Adds a separator into the menu
and returns the corresponding action object.

<a name="qmenu.clear"></a>
### qmenu:clear() ###

Removes all the menu items.
Actions owned by the menu and not shown 
in any other widget are deleted.

<a name="qmenu.exec"></a>
### qmenu:exec([qpoint[, defaultqaction]]) ###

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.

<a name="qmenu.insertMenu"></a>
### qmenu:insertMenu(beforeqaction, newqmenu) ###

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.

<a name="qmenu.insertSeparator"></a>
### qmenu:insertSeparator(beforeqaction) ###

Inserts a new separator before action `beforeqaction` 
and returns the corresponding action object.

<a name="qmenu.menuAction"></a>
### qmenu:menuAction() ###

Returns the action associated with the menu `qmenu`.

<a name="qmenubar"></a>
## qt,QMenuBar ##

Qt class 
[QMenuBar](http://doc.trolltech.com/4.4/qmenu.html) 
provides a horizontal menu bar for use in main windows.
This is a subclass of [qt.QWidget](#qwidget).

Example:
```lua
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()
```

<a name="qmenubar.addMenu"></a>
### qmenubar:addMenu(qmenu) ###

Adds the menu `qmenu` as a menu of the menubar `qmenubar`
and returns the corresponding action object.

<a name="qmenubar.addMenu"></a>
### qmenubar:addMenu([icon,] text) ###

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`.

<a name="qmenubar.clear"></a>
### qmenubar:clear() ###

Removes all the menus and actions from the menu bar.
Actions owned by the menu and not shown 
in any other widget are deleted.

<a name="qmenubar.insertMenu"></a>
### qmenubar:insertMenu(beforeqaction, qmenu) ###

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.

<a name="qmenubar.insertSeparator"></a>
### qmenubar:insertSeparator(beforeqaction) ###

Inserts a new separator before action `beforeqaction` 
and returns the corresponding action object.

<a name="qpainterpath"></a>
## qt.QPainterPath ##

Qt class 
[QPainterPath](http://doc.trolltech.com/4.4/qpainterpath.html) 
represents mathematical boundaries delimiting
regions that can be painted using [painter:fill](qtwidget.md#painterfill) 
or delimited using [painter:stroke](qtwidget.md#painterstroke).
No specific Lua methods have been defined for this Qt variant class.


<a name="qpixmap"></a>
## qt.QPixmap ##

Qt class 
[QPixmap](http://doc.trolltech.com/4.4/qpixmap.html) 
represents a server-side image containing device-dependent data.
No specific Lua methods have been defined for this Qt variant class.


<a name="qpen"></a>
## qt.QPen ##

Qt class 
[QPen](http://doc.trolltech.com/4.4/qpen.html) 
represents the painter settings that determine how 
lines are drawn.

<a name="qpen"></a>
### qt.QPen(table) ###
<a name="qpenfromtable"></a>

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](http://doc.trolltech.com/4.4/qt.html#PenStyle-enum). The default style is `SolidLine`.
  * Field `brush` contains a `qt.QBrush` value that defines the appearance of the painted areas.
  * Field `color` contains a `qt.QColor` value for the brush color. Setting this field is equivalent to setting field `brush` with a solid brush of the specified color. Field `brush` 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` to `true` 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](http://doc.trolltech.com/4.4/qt.html#PenStyle-enum) which determines 
  * Field `joinStyle` specifies the name of the [pen join style](http://doc.trolltech.com/4.4/qt.html#PenJoinStyle-enum) which determines how lines meet with different angles. The default join style is `BevelJoin`.
  * Field `capStyle` specifies the name of the [pen cap style](http://doc.trolltech.com/4.4/qt.html#PenCapStyle-enum) which determines how lines end are drawn. The default cap style is `SquareCap`.
  * Numerical field `miterLimit` determines how far a [miter join](http://doc.trolltech.com/4.4/qpen.html#setMiterLimit) can extend from the join point. This is used to reduce artifacts between line joins where the lines are close to parallel.


<a name="qpen.totable"></a>
### qpen:totable() ###

Expression `qpen:totable()` returns a table describing the pen.
See the documentation of [qt.QPen(table)](#qpenfromtable)
for a description of the table fields.


<a name="qtransform"></a>
## qt.QTransform ##

Qt class 
[QTransform](http://doc.trolltech.com/4.4/qtransform.html) 
represents a 2D transformation of a coordinate system.
Transformation matrices are represented as Qt variants 
of class `qt.QTransform`.

<a name="qtransform"></a>
### qt.QTransform([table[,table]]) ###
<a name="qtransformfromtable"></a>

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](qtcore.md#qpoint) representing the four corners of the quad.

<a name="qtransform.totable"></a>
### qtransform:totable() ###

Expression `qtransform:totable()` returns a table suitable
for use with expression [qt.QTransform(table)](#qtransformfromtable).

<a name="qtransform.scaled"></a>
### qtransform:scaled(sx,sy) ###

Function `qtransform:scaled` returns a new transformation matrix
representing a coordinate system whose axes have been
scaled by coefficient `sx` and `sy`.  

<a name="qtransform.translated"></a>
### qtransform:translated(dx,dy) ###

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.


<a name="qtransform.sheared"></a>
### qtransform:sheared(cx,cy) ###

Function `qtransform:sheared` returns a new transformation matrix
representing a coordinate system that has been sheared using coefficients
`cx` horizontally and `cy` vertically.


<a name="qtransform.rotated"></a>
### qtransform:rotated(angle,[axis,[unit]]) ###

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`.

<a name="qtransform.inverted"></a>
### qtransform:inverted() ###

Function `qtransform:inverted` returns 
the inverse transform of its argument
or `nil` when it is not invertible.

<a name="qtransform.map"></a>
### qtransform:map(...) ###

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.

<a name="qwidget"></a>
## qt.QWidget ##

Qt class 
[QWidget](http://doc.trolltech.com/4.4/qwidget.html) 
is the base class of all graphical interface components.
All widgets inherit class `qt.QWidget` and
its superclass [qt.QObject](qtcore.md#qobject).

<a name="qwidget"></a>
### qt.QWidget([parent]) ###

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](qt.md#qt.qcall) 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.


<a name="qwidget.actions"></a>
### qwidget:actions() ###

Expression `qwidget:actions()` returns a 
qt value of class [qt.QVariantList](qtcore.md#qvariantlist)
containing list of actions associated with this widget.

<a name="qwidget.addAction"></a>
### qwidget:addAction(qaction) ###

Appends action `qaction` to the 
list of actions associated with this widget.

Example: creating a context menu
```lua
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'
```

<a name="qwidget.insertAction"></a>
### qwidget:insertAction(beforeqaction, qaction) ###

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.

<a name="qwidget.mapToGlobal"></a>
### qwidget:mapToGlobal(qpoint) ###

Translates the widget coordinates `qpoint` to global screen coordinates.
Both argument `qpoint` and the return value are Qt value of class
[qt.QPoint](qtcore.md#qpoint).

<a name="qwidget.mapFromGlobal"></a>
### qwidget:mapFromGlobal(qpoint) ###

Translates the global screen coordinates `qpoint` to widget coordinates.
Both argument `qpoint` and the return value are Qt value of class
[qt.QPoint](qtcore.md#qpoint).    


<a name="qwidget.removeAction"></a>
### qwidget:removeAction(qaction) ###

Removes action `qaction` from the 
list actions associated with this widget.


<a name="qwidget.render"></a>
### qwidget:render([pointer]) ###

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](qtwidget.md#painterpainter) or
[painter:device](qtwidget.md#painterdevice).
When such an argument is specified,
nothing is returned.

<a name="qwidget.setAttribute"></a>
### qwidget:setAttribute(widgetattribute,[value]) ###

Sets the specified
[widget attribute](http://doc.trolltech.com/4.4/qt.html#WidgetAttribute-enum)
to boolean value `value`.
Some of these flags are used internally by Qt. 
Care is required.

<a name="qwidget.setWindowFlag"></a>
### qwidget:setWindowFlag(windowflag,[value]) ###

Sets the specified
[window flag](http://doc.trolltech.com/4.4/qt.html#WindowType-enum)
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.

<a name="qwidget.testAttribute"></a>
### qwidget:testAttribute(widgetattribute) ###

Returns a boolean indicating the value of the specified
[widget attribute](http://doc.trolltech.com/4.4/qt.html#WidgetAttribute-enum).
Flags indicating a window type 
are handled as exclusive flags.

<a name="qwidget.testWindowFlag"></a>
### qwidget:testWindowFlag(windowflag) ###

Returns a boolean indicating the value of the specified
[window flag](http://doc.trolltech.com/4.4/qt.html#WindowType-enum).
Flags indicating a window type 
are handled as exclusive flags.

<a name="qwidget.window"></a>
### qwidget:window() ###

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`.

```lua
qwidget:window().windowTitle "New Title"
```