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
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
|
/****************************************************************************
**
** Implementation of QWidget class
**
** Created : 931031
**
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the kernel module of the Qt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free Qt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.QPL
** included in the packaging of this file. Licensees holding valid Qt
** Commercial licenses may use this file in accordance with the Qt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/
#include "qobjectlist.h"
#include "qwidget.h"
#include "qwidgetlist.h"
#include "qwidgetintdict.h"
#include "qptrdict.h"
#include "qfocusdata.h"
#include "qcursor.h"
#include "qpixmap.h"
#include "qapplication.h"
#include "qapplication_p.h"
#include "qbrush.h"
#include "qlayout.h"
#include "qstylefactory.h"
#include "qcleanuphandler.h"
#include "qstyle.h"
#include "qmetaobject.h"
#include "qguardedptr.h"
#if defined(QT_THREAD_SUPPORT)
#include "qthread.h"
#endif
#if defined(QT_ACCESSIBILITY_SUPPORT)
#include "qaccessible.h"
#endif
#if defined(Q_WS_WIN)
#include "qt_windows.h"
#include "qinputcontext_p.h"
#endif
#if defined(Q_WS_QWS)
#include "qwsmanager_qws.h"
#endif
#include "qfontdata_p.h"
/*!
\class QWidget qwidget.h
\brief The QWidget class is the base class of all user interface objects.
\ingroup abstractwidgets
\mainclass
The widget is the atom of the user interface: it receives mouse,
keyboard and other events from the window system, and paints a
representation of itself on the screen. Every widget is
rectangular, and they are sorted in a Z-order. A widget is
clipped by its parent and by the widgets in front of it.
A widget that isn't embedded in a parent widget is called a
top-level widget. Usually, top-level widgets are windows with a
frame and a title bar (although it is also possible to create
top-level widgets without such decoration if suitable widget flags
are used). In Qt, QMainWindow and the various subclasses of
QDialog are the most common top-level windows.
A widget without a parent widget is always a top-level widget.
Non-top-level widgets are child widgets. These are child windows
in their parent widgets. You cannot usually distinguish a child
widget from its parent visually. Most other widgets in Qt are
useful only as child widgets. (It is possible to make, say, a
button into a top-level widget, but most people prefer to put
their buttons inside other widgets, e.g. QDialog.)
If you want to use a QWidget to hold child widgets you will
probably want to add a layout to the parent QWidget. (See \link
layout.html Layouts\endlink.)
QWidget has many member functions, but some of them have little
direct functionality: for example, QWidget has a font property,
but never uses this itself. There are many subclasses which
provide real functionality, such as QPushButton, QListBox and
QTabDialog, etc.
\section1 Groups of functions:
\table
\header \i Context \i Functions
\row \i Window functions \i
show(),
hide(),
raise(),
lower(),
close().
\row \i Top level windows \i
caption(),
setCaption(),
icon(),
setIcon(),
iconText(),
setIconText(),
isActiveWindow(),
setActiveWindow(),
showMinimized().
showMaximized(),
showFullScreen(),
showNormal().
\row \i Window contents \i
update(),
repaint(),
erase(),
scroll(),
updateMask().
\row \i Geometry \i
pos(),
size(),
rect(),
x(),
y(),
width(),
height(),
sizePolicy(),
setSizePolicy(),
sizeHint(),
updateGeometry(),
layout(),
move(),
resize(),
setGeometry(),
frameGeometry(),
geometry(),
childrenRect(),
adjustSize(),
mapFromGlobal(),
mapFromParent()
mapToGlobal(),
mapToParent(),
maximumSize(),
minimumSize(),
sizeIncrement(),
setMaximumSize(),
setMinimumSize(),
setSizeIncrement(),
setBaseSize(),
setFixedSize()
\row \i Mode \i
isVisible(),
isVisibleTo(),
isMinimized(),
isDesktop(),
isEnabled(),
isEnabledTo(),
isModal(),
isPopup(),
isTopLevel(),
setEnabled(),
hasMouseTracking(),
setMouseTracking(),
isUpdatesEnabled(),
setUpdatesEnabled(),
clipRegion().
\row \i Look and feel \i
style(),
setStyle(),
cursor(),
setCursor()
font(),
setFont(),
palette(),
setPalette(),
backgroundMode(),
setBackgroundMode(),
colorGroup(),
fontMetrics(),
fontInfo().
\row \i Keyboard focus<br>functions \i
isFocusEnabled(),
setFocusPolicy(),
focusPolicy(),
hasFocus(),
setFocus(),
clearFocus(),
setTabOrder(),
setFocusProxy().
\row \i Mouse and<br>keyboard grabbing \i
grabMouse(),
releaseMouse(),
grabKeyboard(),
releaseKeyboard(),
mouseGrabber(),
keyboardGrabber().
\row \i Event handlers \i
event(),
mousePressEvent(),
mouseReleaseEvent(),
mouseDoubleClickEvent(),
mouseMoveEvent(),
keyPressEvent(),
keyReleaseEvent(),
focusInEvent(),
focusOutEvent(),
wheelEvent(),
enterEvent(),
leaveEvent(),
paintEvent(),
moveEvent(),
resizeEvent(),
closeEvent(),
dragEnterEvent(),
dragMoveEvent(),
dragLeaveEvent(),
dropEvent(),
childEvent(),
showEvent(),
hideEvent(),
customEvent().
\row \i Change handlers \i
enabledChange(),
fontChange(),
paletteChange(),
styleChange(),
windowActivationChange().
\row \i System functions \i
parentWidget(),
topLevelWidget(),
reparent(),
polish(),
winId(),
find(),
metric().
\row \i What's this help \i
customWhatsThis()
\row \i Internal kernel<br>functions \i
focusNextPrevChild(),
wmapper(),
clearWFlags(),
getWFlags(),
setWFlags(),
testWFlags().
\endtable
Every widget's constructor accepts two or three standard arguments:
\list 1
\i \c{QWidget *parent = 0} is the parent of the new widget.
If it is 0 (the default), the new widget will be a top-level window.
If not, it will be a child of \e parent, and be constrained by \e
parent's geometry (unless you specify \c WType_TopLevel as
widget flag).
\i \c{const char *name = 0} is the widget name of the new
widget. You can access it using name(). The widget name is little
used by programmers but is quite useful with GUI builders such as
\e{Qt Designer} (you can name a widget in \e{Qt Designer}, and
connect() to it using the name in your code). The dumpObjectTree()
debugging function also uses it.
\i \c{WFlags f = 0} (where available) sets the widget flags; the
default is suitable for almost all widgets, but to get, for
example, a top-level widget without a window system frame, you
must use special flags.
\endlist
The tictac/tictac.cpp example program is good example of a simple
widget. It contains a few event handlers (as all widgets must), a
few custom routines that are specific to it (as all useful widgets
do), and has a few children and connections. Everything it does
is done in response to an event: this is by far the most common way
to design GUI applications.
You will need to supply the content for your widgets yourself, but
here is a brief run-down of the events, starting with the most common
ones:
\list
\i paintEvent() - called whenever the widget needs to be
repainted. Every widget which displays output must implement it,
and it is wise \e not to paint on the screen outside
paintEvent().
\i resizeEvent() - called when the widget has been resized.
\i mousePressEvent() - called when a mouse button is pressed.
There are six mouse-related events, but the mouse press and mouse
release events are by far the most important. A widget receives
mouse press events when the mouse is inside it, or when it has
grabbed the mouse using grabMouse().
\i mouseReleaseEvent() - called when a mouse button is released.
A widget receives mouse release events when it has received the
corresponding mouse press event. This means that if the user
presses the mouse inside \e your widget, then drags the mouse to
somewhere else, then releases, \e your widget receives the release
event. There is one exception: if a popup menu appears while the
mouse button is held down, this popup immediately steals the mouse
events.
\i mouseDoubleClickEvent() - not quite as obvious as it might seem.
If the user double-clicks, the widget receives a mouse press event
(perhaps a mouse move event or two if they don't hold the mouse
quite steady), a mouse release event and finally this event. It is
\e{not possible} to distinguish a click from a double click until you've
seen whether the second click arrives. (This is one reason why most GUI
books recommend that double clicks be an extension of single clicks,
rather than trigger a different action.)
\endlist
If your widget only contains child widgets, you probably do not need to
implement any event handlers. If you want to detect a mouse click in
a child widget call the child's hasMouse() function inside the
parent widget's mousePressEvent().
Widgets that accept keyboard input need to reimplement a few more
event handlers:
\list
\i keyPressEvent() - called whenever a key is pressed, and again
when a key has been held down long enough for it to auto-repeat.
Note that the Tab and Shift+Tab keys are only passed to the widget
if they are not used by the focus-change mechanisms. To force those
keys to be processed by your widget, you must reimplement
QWidget::event().
\i focusInEvent() - called when the widget gains keyboard focus
(assuming you have called setFocusPolicy()). Well written widgets
indicate that they own the keyboard focus in a clear but discreet
way.
\i focusOutEvent() - called when the widget loses keyboard focus.
\endlist
Some widgets will also need to reimplement some of the less common
event handlers:
\list
\i mouseMoveEvent() - called whenever the mouse moves while a
button is held down. This is useful for, for example, dragging. If
you call setMouseTracking(TRUE), you get mouse move events even
when no buttons are held down. (Note that applications which make
use of mouse tracking are often not very useful on low-bandwidth X
connections.) (See also the \link dnd.html drag and drop\endlink
information.)
\i keyReleaseEvent() - called whenever a key is released, and also
while it is held down if the key is auto-repeating. In that case
the widget receives a key release event and immediately a key press
event for every repeat. Note that the Tab and Shift+Tab keys are
only passed to the widget if they are not used by the focus-change
mechanisms. To force those keys to be processed by your widget, you
must reimplement QWidget::event().
\i wheelEvent() -- called whenever the user turns the mouse wheel
while the widget has the focus.
\i enterEvent() - called when the mouse enters the widget's screen
space. (This excludes screen space owned by any children of the
widget.)
\i leaveEvent() - called when the mouse leaves the widget's screen
space.
\i moveEvent() - called when the widget has been moved relative to its
parent.
\i closeEvent() - called when the user closes the widget (or when
close() is called).
\endlist
There are also some rather obscure events. They are listed in
\c qevent.h and you need to reimplement event() to handle them.
The default implementation of event() handles Tab and Shift+Tab
(to move the keyboard focus), and passes on most other events to
one of the more specialized handlers above.
When implementing a widget, there are a few more things to
consider.
\list
\i In the constructor, be sure to set up your member variables
early on, before there's any chance that you might receive an event.
\i It is almost always useful to reimplement sizeHint() and to set
the correct size policy with setSizePolicy(), so users of your class
can set up layout management more easily. A size policy lets you
supply good defaults for the layout management handling, so that
other widgets can contain and manage yours easily. sizeHint()
indicates a "good" size for the widget.
\i If your widget is a top-level window, setCaption() and setIcon() set
the title bar and icon respectively.
\endlist
\sa QEvent, QPainter, QGridLayout, QBoxLayout
*/
/*****************************************************************************
Internal QWidgetMapper class
The purpose of this class is to map widget identifiers to QWidget objects.
All QWidget objects register themselves in the QWidgetMapper when they
get an identifier. Widgets unregister themselves when they change ident-
ifier or when they are destroyed. A widget identifier is really a window
handle.
The widget mapper is created and destroyed by the main application routines
in the file qapp_xxx.cpp.
*****************************************************************************/
#if defined(Q_WS_QWS) || defined(Q_OS_TEMP)
static const int WDictSize = 163; // plenty for small devices
#else
static const int WDictSize = 1123; // plenty for 5 big complex windows
#endif
class QWidgetMapper : public QWidgetIntDict
{ // maps ids -> widgets
public:
QWidgetMapper();
~QWidgetMapper();
QWidget *find( WId id ); // find widget
void insert( const QWidget * ); // insert widget
bool remove( WId id ); // remove widget
private:
WId cur_id;
QWidget *cur_widget;
};
QWidgetMapper *QWidget::mapper = 0; // app global widget mapper
QWidgetMapper::QWidgetMapper() : QWidgetIntDict(WDictSize)
{
cur_id = 0;
cur_widget = 0;
}
QWidgetMapper::~QWidgetMapper()
{
clear();
}
inline QWidget *QWidgetMapper::find( WId id )
{
if ( id != cur_id ) { // need to lookup
cur_widget = QWidgetIntDict::find((long)id);
if ( cur_widget )
cur_id = id;
else
cur_id = 0;
}
return cur_widget;
}
inline void QWidgetMapper::insert( const QWidget *widget )
{
QWidgetIntDict::insert((long)widget->winId(),widget);
}
inline bool QWidgetMapper::remove( WId id )
{
if ( cur_id == id ) { // reset current widget
cur_id = 0;
cur_widget = 0;
}
return QWidgetIntDict::remove((long)id);
}
/*****************************************************************************
QWidget utility functions
*****************************************************************************/
static QFont qt_naturalWidgetFont( QWidget* w ) {
QFont naturalfont = QApplication::font( w );
if ( ! w->isTopLevel() ) {
if ( ! naturalfont.isCopyOf( QApplication::font() ) )
naturalfont = naturalfont.resolve( w->parentWidget()->font() );
else
naturalfont = w->parentWidget()->font();
}
return naturalfont;
}
#ifndef QT_NO_PALETTE
static QPalette qt_naturalWidgetPalette( QWidget* w ) {
QPalette naturalpalette = QApplication::palette( w );
if ( !w->isTopLevel() && naturalpalette.isCopyOf( QApplication::palette() ) )
naturalpalette = w->parentWidget()->palette();
return naturalpalette;
}
#endif
QSize qt_naturalWidgetSize( QWidget *w ) {
QSize s = w->sizeHint();
QSizePolicy::ExpandData exp;
#ifndef QT_NO_LAYOUT
if ( w->layout() ) {
if ( w->layout()->hasHeightForWidth() )
s.setHeight( w->layout()->totalHeightForWidth( s.width() ) );
exp = w->layout()->expanding();
} else
#endif
{
if ( w->sizePolicy().hasHeightForWidth() )
s.setHeight( w->heightForWidth( s.width() ) );
exp = w->sizePolicy().expanding();
}
if ( exp & QSizePolicy::Horizontally )
s.setWidth( QMAX( s.width(), 200 ) );
if ( exp & QSizePolicy::Vertically )
s.setHeight( QMAX( s.height(), 150 ) );
#if defined(Q_WS_X11)
QRect screen = QApplication::desktop()->screenGeometry( w->x11Screen() );
#else // all others
QRect screen = QApplication::desktop()->screenGeometry( w->pos() );
#endif
s.setWidth( QMIN( s.width(), screen.width()*2/3 ) );
s.setHeight( QMIN( s.height(), screen.height()*2/3 ) );
return s;
}
/*****************************************************************************
QWidget member functions
*****************************************************************************/
/*
Widget state flags:
\list
\i WState_Created The widget has a valid winId().
\i WState_Disabled The widget does not receive any mouse or keyboard
events.
\i WState_ForceDisabled The widget is explicitly disabled, i.e. it
will remain disabled even when all its ancestors are set to the enabled
state. This implies WState_Disabled.
\i WState_Visible The widget is currently visible.
\i WState_ForceHide The widget is explicitly hidden, i.e. it won't
become visible unless you call show() on it. WState_ForceHide
implies !WState_Visible.
\i WState_OwnCursor A cursor has been set for this widget.
\i WState_MouseTracking Mouse tracking is enabled.
\i WState_CompressKeys Compress keyboard events.
\i WState_BlockUpdates Repaints and updates are disabled.
\i WState_InPaintEvent Currently processing a paint event.
\i WState_Reparented The widget has been reparented.
\i WState_ConfigPending A configuration (resize/move) event is pending.
\i WState_Resized The widget has been resized.
\i WState_AutoMask The widget has an automatic mask, see setAutoMask().
\i WState_Polished The widget has been "polished" (i.e. late
initialization) by a QStyle.
\i WState_DND The widget supports drag and drop, see setAcceptDrops().
\i WState_Exposed the widget was finally exposed (X11 only,
helps avoid paint event doubling).
\i WState_HasMouse The widget is under the mouse cursor.
\endlist
*/
/*! \enum Qt::WFlags
\internal */
/*! \enum Qt::WState
\internal */
/*!
\enum Qt::WidgetFlags
\keyword widget flag
This enum type is used to specify various window-system properties
for the widget. They are fairly unusual but necessary in a few
cases. Some of these flags depend on whether the underlying window
manager supports them. (See the \link toplevel-example.html
toplevel example\endlink for an explanation and example of their
use.)
The main types are
\value WType_TopLevel indicates that this widget is a top-level
widget, usually with a window-system frame and so on.
\value WType_Dialog indicates that this widget is a top-level
window that should be decorated as a dialog (i.e. typically no
maximize or minimize buttons in the title bar). If you want to use
it as a modal dialog it should be launched from another window, or
have a parent and this flag should be combined with \c WShowModal.
If you make it modal, the dialog will prevent other top-level
windows in the application from getting any input. \c WType_Dialog
implies \c WType_TopLevel. We refer to a top-level window that has
a parent as a \e secondary window. (See also \c WGroupLeader.)
\value WType_Popup indicates that this widget is a popup
top-level window, i.e. that it is modal, but has a window system
frame appropriate for popup menus. \c WType_Popup implies
WType_TopLevel.
\value WType_Desktop indicates that this widget is the desktop.
See also \c WPaintDesktop below. \c WType_Desktop implies \c
WType_TopLevel.
There are also a number of flags which you can use to customize
the appearance of top-level windows. These have no effect on other
windows:
\value WStyle_Customize indicates that the \c WStyle_* flags
should be used to build the window instead of the default flags.
\value WStyle_NormalBorder gives the window a normal border.
This cannot be combined with \c WStyle_DialogBorder or \c
WStyle_NoBorder.
\value WStyle_DialogBorder gives the window a thin dialog border.
This cannot be combined with \c WStyle_NormalBorder or \c
WStyle_NoBorder.
\value WStyle_NoBorder produces a borderless window. Note that
the user cannot move or resize a borderless window via the window
system. This cannot be combined with \c WStyle_NormalBorder or \c
WStyle_DialogBorder. On Windows, the flag works fine. On X11, the
result of the flag is dependent on the window manager and its
ability to understand MOTIF and/or NETWM hints: most existing
modern window managers can handle this. With \c WX11BypassWM, you
can bypass the window manager completely. This results in a
borderless window that is not managed at all (i.e. no keyboard
input unless you call setActiveWindow() manually).
\value WStyle_NoBorderEx this value is obsolete. It has the same
effect as using \c WStyle_NoBorder.
\value WStyle_Title gives the window a title bar.
\value WStyle_SysMenu adds a window system menu.
\value WStyle_Minimize adds a minimize button. Note that on
Windows this has to be combined with \c WStyle_SysMenu for it to
work.
\value WStyle_Maximize adds a maximize button. Note that on
Windows this has to be combined with \c WStyle_SysMenu for it to work.
\value WStyle_MinMax is equal to \c
WStyle_Minimize|WStyle_Maximize. Note that on Windows this has to
be combined with \c WStyle_SysMenu to work.
\value WStyle_ContextHelp adds a context help button to dialogs.
\value WStyle_Tool makes the window a tool window. A tool window
is often a small window with a smaller than usual title bar and
decoration, typically used for collections of tool buttons. It
there is a parent, the tool window will always be kept on top of
it. If there isn't a parent, you may consider passing \c
WStyle_StaysOnTop as well. If the window system supports it, a
tool window can be decorated with a somewhat lighter frame. It can
also be combined with \c WStyle_NoBorder.
\value WStyle_StaysOnTop informs the window system that the
window should stay on top of all other windows. Note that on some
window managers on X11 you also have to pass \c WX11BypassWM for
this flag to work correctly.
\value WStyle_Dialog indicates that the window is a logical
subwindow of its parent (i.e. a dialog). The window will not get
its own taskbar entry and will be kept on top of its parent by the
window system. Usually it will also be minimized when the parent
is minimized. If not customized, the window is decorated with a
slightly simpler title bar. This is the flag QDialog uses.
\value WStyle_Splash indicates that the window is a splash screen.
On X11, we try to follow NETWM standard for a splash screen window if the
window manager supports is otherwise it is equivalent to \c WX11BypassWM. On
other platforms, it is equivalent to \c WStyle_NoBorder \c | \c WMacNoSheet \c |
\c WStyle_Tool \c | \c WWinOwnDC
Modifier flags:
\value WDestructiveClose makes Qt delete this widget when the
widget has accepted closeEvent(), or when the widget tried to
ignore closeEvent() but could not.
\value WPaintDesktop gives this widget paint events for the
desktop.
\value WPaintUnclipped makes all painters operating on this
widget unclipped. Children of this widget or other widgets in
front of it do not clip the area the painter can paint on.
\value WPaintClever indicates that Qt should \e not try to
optimize repainting for the widget, but instead pass on window
system repaint events directly. (This tends to produce more events
and smaller repaint regions.)
\value WMouseNoMask indicates that even if the widget has a mask,
it wants mouse events for its entire rectangle.
\value WStaticContents indicates that the widget contents are
north-west aligned and static. On resize, such a widget will
receive paint events only for the newly visible part of itself.
\value WNoAutoErase indicates that the widget paints all its
pixels. Updating, resizing, scrolling and focus changes should
therefore not erase the widget. This allows smart-repainting to
avoid flicker.
\value WResizeNoErase this value is obsolete; use WNoAutoErase instead.
\value WRepaintNoErase this value is obsolete; use WNoAutoErase instead.
\value WGroupLeader makes this window a group leader. A group
leader should \e not have a parent (i.e. it should be a top-level
window). Any decendant windows (direct or indirect) of a group
leader are in its group; other windows are not. If you show a
secondary window from the group (i.e. show a window whose top-most
parent is a group leader), that window will be modal with respect
to the other windows in the group, but modeless with respect to
windows in other groups.
Miscellaneous flags
\value WShowModal see WType_Dialog
Internal flags.
\value WNoMousePropagation
\value WStaticContents
\value WStyle_Reserved
\value WSubWindow
\value WType_Modal
\value WWinOwnDC
\value WX11BypassWM
\value WMacNoSheet
\value WMacDrawer
\value WStyle_Mask
\value WType_Mask
*/
/*!
\enum Qt::NETWMFlags
\keyword NETWM flag
This enum type is used to specify various NETWM properties
under X11 and similar systems.
The main types are
\value WX11DisableMove
\value WX11DisableClose
\value WX11DisableResize
\value WX11DisableMinimize
\value WX11DisableMaximize
\value WX11DisableShade
*/
/*!
\enum Qt::WidgetState
Internal flags.
\value WState_Created
\value WState_Disabled
\value WState_Visible
\value WState_ForceHide
\value WState_OwnCursor
\value WState_MouseTracking
\value WState_CompressKeys
\value WState_BlockUpdates
\value WState_InPaintEvent
\value WState_Reparented
\value WState_ConfigPending
\value WState_Resized
\value WState_AutoMask
\value WState_Polished
\value WState_DND
\value WState_Reserved0 \e internal
\value WState_CreatedHidden
\value WState_Maximized
\value WState_Minimized
\value WState_ForceDisabled
\value WState_Exposed
\value WState_HasMouse
\value WState_CreatedHidden
\value WState_OwnSizePolicy
\value WState_FullScreen
*/
/*!
\enum Qt::WindowState
\keyword window state
This enum type is used to specify the current state of a top-level
window.
The states are
\value WindowNoState The window has no state set (in normal state).
\value WindowMinimized The window is minimized (i.e. iconified).
\value WindowMaximized The window is maximized with a frame around it.
\value WindowFullScreen The window fills the entire screen without any frame around it.
\value WindowActive The window is the active window, i.e. it has keyboard focus.
*/
/*!
Constructs a widget which is a child of \a parent, with the name
\a name, widget flags set to \a f, and NETWM flags set to \a n.
If \a parent is 0, the new widget becomes a top-level window. If
\a parent is another widget, this widget becomes a child window
inside \a parent. The new widget is deleted when its \a parent is
deleted.
The \a name is sent to the QObject constructor.
The widget flags argument, \a f, is normally 0, but it can be set
to customize the window frame of a top-level widget (i.e. \a
parent must be 0). To customize the frame, set the \c
WStyle_Customize flag OR'ed with any of the \l Qt::WidgetFlags.
If you add a child widget to an already visible widget you must
explicitly show the child to make it visible.
Note that the X11 version of Qt may not be able to deliver all
combinations of style flags on all systems. This is because on
X11, Qt can only ask the window manager, and the window manager
can override the application's settings. On Windows, Qt can set
whatever flags you want.
Example:
\code
QLabel *splashScreen = new QLabel( 0, "mySplashScreen",
WStyle_Customize | WStyle_Splash );
\endcode
*/
QWidget::QWidget( QWidget *parent, const char *name, WFlags f, NFlags n )
: QObject( parent, name ), QPaintDevice( QInternal::Widget )
{
#if defined(QT_CHECK_STATE) && !defined(Q_WS_WIN)
if ( qApp->type() == QApplication::Tty ) {
qWarning( "QWidget: Cannot create a QWidget when no GUI "
"is being used" );
}
#endif
#if defined(QT_THREAD_SUPPORT) && defined(QT_CHECK_STATE)
if (QThread::currentThreadObject() != QApplication::guiThread()) {
qFatal( "QWidget: Cannot create a QWidget outside of the main GUI thread" );
}
#endif
fstrut_dirty = 1;
isWidget = TRUE; // is a widget
winid = 0; // default attributes
widget_state = 0;
widget_flags = f;
netwm_flags = n;
focus_policy = 0;
own_font = 0;
own_palette = 0;
sizehint_forced = 0;
is_closing = 0;
in_show = 0;
in_show_maximized = 0;
im_enabled = FALSE;
#ifndef QT_NO_LAYOUT
lay_out = 0;
#endif
extra = 0; // no extra widget info
#ifndef QT_NO_PALETTE
bg_col = pal.active().background(); // default background color
#endif
create(); // platform-dependent init
#ifndef QT_NO_PALETTE
pal = isTopLevel() ? QApplication::palette() : parentWidget()->palette();
#endif
if ( ! isTopLevel() )
fnt = parentWidget()->font();
#if defined(Q_WS_X11)
fnt.x11SetScreen( x11Screen() );
#endif // Q_WS_X11
if ( !isDesktop() )
setBackgroundFromMode(); //### parts of this are done in create but not all (see reparent(...) )
// make sure move/resize events are sent to all widgets
QApplication::postEvent( this, new QMoveEvent( crect.topLeft(),
crect.topLeft() ) );
QApplication::postEvent( this, new QResizeEvent(crect.size(),
crect.size()) );
if ( isTopLevel() ) {
setWState( WState_ForceHide | WState_CreatedHidden );
QFocusData *fd = focusData( TRUE );
if ( fd->focusWidgets.findRef(this) < 0 )
fd->focusWidgets.append( this );
} else {
// propagate enabled state
if ( !parentWidget()->isEnabled() )
setWState( WState_Disabled );
// new widgets do not show up in already visible parents
if ( parentWidget()->isVisible() )
setWState( WState_ForceHide | WState_CreatedHidden );
}
if ( ++instanceCounter > maxInstances )
maxInstances = instanceCounter;
}
/*!
Destroys the widget.
All this widget's children are deleted first. The application
exits if this widget is the main widget.
*/
QWidget::~QWidget()
{
#if defined (QT_CHECK_STATE)
if ( paintingActive() )
qWarning( "%s (%s): deleted while being painted", className(), name() );
#endif
// Remove myself and all children from the can-take-focus list
QFocusData *f = focusData( FALSE );
if ( f ) {
QPtrListIterator<QWidget> it(f->focusWidgets);
QWidget *w;
while ( (w = it.current()) ) {
++it;
QWidget * p = w;
while( p && p != this )
p = p->parentWidget();
if ( p ) // my descendant
f->focusWidgets.removeRef( w );
}
}
--instanceCounter;
if ( QApplication::main_widget == this ) { // reset main widget
QApplication::main_widget = 0;
if (qApp)
qApp->quit();
}
if ( hasFocus() )
clearFocus();
if ( isTopLevel() && isShown() && winId() )
hide();
// A parent widget must destroy all its children before destroying itself
if ( childObjects ) { // delete children objects
QObjectListIt it(*childObjects);
QObject *obj;
while ( (obj=it.current()) ) {
++it;
obj->parentObj = 0;
childObjects->removeRef( obj );
delete obj;
}
delete childObjects;
childObjects = 0;
}
QApplication::removePostedEvents( this );
destroy(); // platform-dependent cleanup
if ( extra )
deleteExtra();
}
int QWidget::instanceCounter = 0; // Current number of widget instances
int QWidget::maxInstances = 0; // Maximum number of widget instances
/*!
\internal
Creates the global widget mapper.
The widget mapper converts window handles to widget pointers.
\sa destroyMapper()
*/
void QWidget::createMapper()
{
mapper = new QWidgetMapper;
Q_CHECK_PTR( mapper );
}
/*!
\internal
Destroys the global widget mapper.
\sa createMapper()
*/
void QWidget::destroyMapper()
{
if ( !mapper ) // already gone
return;
QWidgetIntDictIt it( *((QWidgetIntDict*)mapper) );
QWidgetMapper * myMapper = mapper;
mapper = 0;
QWidget *w;
while ( (w=it.current()) ) { // remove parents widgets
++it;
if ( !w->parentObj ) // widget is a parent
w->destroy( TRUE, TRUE );
}
delete myMapper;
}
static QWidgetList *wListInternal( QWidgetMapper *mapper, bool onlyTopLevel )
{
QWidgetList *list = new QWidgetList;
Q_CHECK_PTR( list );
if ( mapper ) {
QWidget *w;
QWidgetIntDictIt it( *((QWidgetIntDict*)mapper) );
while ( (w=it.current()) ) {
++it;
if ( !onlyTopLevel || w->isTopLevel() )
list->append( w );
}
}
return list;
}
/*!
\internal
Returns a list of all widgets.
\sa tlwList(), QApplication::allWidgets()
*/
QWidgetList *QWidget::wList()
{
return wListInternal( mapper, FALSE );
}
/*!
\internal
Returns a list of all top level widgets.
\sa wList(), QApplication::topLevelWidgets()
*/
QWidgetList *QWidget::tlwList()
{
return wListInternal( mapper, TRUE );
}
void QWidget::setWinId( WId id ) // set widget identifier
{
if ( !mapper ) // mapper destroyed
return;
if ( winid )
mapper->remove( winid );
winid = id;
#if defined(Q_WS_X11)
hd = id; // X11: hd == ident
#endif
if ( id )
mapper->insert( this );
}
/*!
\internal
Returns a pointer to the block of extra widget data.
*/
QWExtra *QWidget::extraData()
{
return extra;
}
/*!
\internal
Returns a pointer to the block of extra top level widget data.
This data is guaranteed to exist for top level widgets.
*/
QTLWExtra *QWidget::topData()
{
createTLExtra();
return extra->topextra;
}
void QWidget::createTLExtra()
{
if ( !extra )
createExtra();
if ( !extra->topextra ) {
QTLWExtra* x = extra->topextra = new QTLWExtra;
#if defined( Q_WS_WIN ) || defined( Q_WS_MAC )
x->opacity = 255;
#endif
#ifndef QT_NO_WIDGET_TOPEXTRA
x->icon = 0;
#endif
x->focusData = 0;
x->fleft = x->fright = x->ftop = x->fbottom = 0;
x->incw = x->inch = 0;
x->basew = x->baseh = 0;
x->normalGeometry = QRect(0,0,-1,-1);
#if defined(Q_WS_X11)
x->embedded = 0;
x->parentWinId = 0;
x->spont_unmapped = 0;
x->dnd = 0;
x->uspos = 0;
x->ussize = 0;
#endif
x->savedFlags = 0;
#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
x->decor_allocated_region = QRegion();
x->qwsManager = 0;
#endif
createTLSysExtra();
}
}
/*!
\internal
Creates the widget extra data.
*/
void QWidget::createExtra()
{
if ( !extra ) { // if not exists
extra = new QWExtra;
Q_CHECK_PTR( extra );
extra->minw = extra->minh = 0;
extra->maxw = extra->maxh = QWIDGETSIZE_MAX;
extra->bg_pix = 0;
extra->focus_proxy = 0;
#ifndef QT_NO_CURSOR
extra->curs = 0;
#endif
extra->topextra = 0;
extra->bg_mode = PaletteBackground;
extra->bg_mode_visual = PaletteBackground;
extra->bg_origin = WidgetOrigin;
#ifndef QT_NO_STYLE
extra->style = 0;
#endif
extra->size_policy = QSizePolicy( QSizePolicy::Preferred,
QSizePolicy::Preferred );
extra->m_ceData = NULL;
createSysExtra();
}
}
/*!
\internal
Deletes the widget extra data.
*/
void QWidget::deleteExtra()
{
if ( extra ) { // if exists
delete extra->m_ceData;
delete extra->bg_pix;
#ifndef QT_NO_CURSOR
delete extra->curs;
#endif
deleteSysExtra();
if ( extra->topextra ) {
deleteTLSysExtra();
#ifndef QT_NO_WIDGET_TOPEXTRA
delete extra->topextra->icon;
#endif
delete extra->topextra->focusData;
#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
delete extra->topextra->qwsManager;
#endif
delete extra->topextra;
}
delete extra;
// extra->xic destroyed in QWidget::destroy()
extra = 0;
}
}
/*!
\internal
This function is called when a widget is hidden or destroyed.
It resets some application global pointers that should only refer active,
visible widgets.
*/
void QWidget::deactivateWidgetCleanup()
{
// If this was the active application window, reset it
if ( this == QApplication::active_window )
qApp->setActiveWindow( 0 );
// If the is the active mouse press widget, reset it
#ifdef Q_WS_MAC
extern QGuardedPtr<QWidget> qt_button_down;
#else
extern QWidget *qt_button_down;
#endif
if ( this == (QWidget *)qt_button_down )
qt_button_down = 0;
}
/*!
Returns a pointer to the widget with window identifer/handle \a
id.
The window identifier type depends on the underlying window
system, see \c qwindowdefs.h for the actual definition. If there
is no widget with this identifier, 0 is returned.
*/
QWidget *QWidget::find( WId id )
{
return mapper ? mapper->find( id ) : 0;
}
/*!
\fn QWidgetMapper *QWidget::wmapper()
\internal
Returns a pointer to the widget mapper.
The widget mapper is an internal dictionary that is used to map from
window identifiers/handles to widget pointers.
\sa find(), id()
*/
/*!
\fn WFlags QWidget::getWFlags() const
Returns the widget flags for this this widget.
Widget flags are a combination of \l{Qt::WidgetFlags}.
\sa testWFlags(), setWFlags(), clearWFlags()
*/
/*!
\fn void QWidget::setWFlags( WFlags f )
Sets the widget flags \a f.
Widget flags are a combination of \l{Qt::WidgetFlags}.
\sa testWFlags(), getWFlags(), clearWFlags()
*/
/*!
\fn void QWidget::clearWFlags( WFlags f )
Clears the widget flags \a f.
Widget flags are a combination of \l{Qt::WidgetFlags}.
\sa testWFlags(), getWFlags(), setWFlags()
*/
/*!
\fn WId QWidget::winId() const
Returns the window system identifier of the widget.
Portable in principle, but if you use it you are probably about to
do something non-portable. Be careful.
\sa find()
*/
#ifndef QT_NO_STYLE
/*!
Returns the GUI style for this widget
\sa QWidget::setStyle(), QApplication::setStyle(), QApplication::style()
*/
QStyle& QWidget::style() const
{
if ( extra && extra->style )
return *extra->style;
QStyle &ret = qApp->style();
return ret;
}
/*!
Sets the widget's GUI style to \a style. Ownership of the style
object is not transferred.
If no style is set, the widget uses the application's style,
QApplication::style() instead.
Setting a widget's style has no effect on existing or future child
widgets.
\warning This function is particularly useful for demonstration
purposes, where you want to show Qt's styling capabilities. Real
applications should avoid it and use one consistent GUI style
instead.
\sa style(), QStyle, QApplication::style(), QApplication::setStyle()
*/
void QWidget::setStyle( QStyle *style )
{
QStyle& old = QWidget::style();
createExtra();
extra->style = style;
if ( !testWFlags(WType_Desktop) // (except desktop)
&& testWState(WState_Polished)) { // (and have been polished)
old.unPolish( this );
QWidget::style().polish( this );
}
styleChange( old );
}
/*!
\overload
Sets the widget's GUI style to \a style using the QStyleFactory.
*/
QStyle* QWidget::setStyle( const QString &style )
{
QStyle *s = QStyleFactory::create( style );
setStyle( s );
return s;
}
/*!
This virtual function is called when the style of the widgets
changes. \a oldStyle is the previous GUI style; you can get the
new style from style().
Reimplement this function if your widget needs to know when its
GUI style changes. You will almost certainly need to update the
widget using update().
The default implementation updates the widget including its
geometry.
\sa QApplication::setStyle(), style(), update(), updateGeometry()
*/
void QWidget::styleChange( QStyle& /* oldStyle */ )
{
update();
updateGeometry();
}
#endif
/*!
\property QWidget::isTopLevel
\brief whether the widget is a top-level widget
A top-level widget is a widget which usually has a frame and a
\link QWidget::caption caption (title)\endlink. \link
QWidget::isPopup() Popup\endlink and \link QWidget::isDesktop()
desktop\endlink widgets are also top-level widgets.
A top-level widget can have a \link QWidget::parentWidget() parent
widget\endlink. It will then be grouped with its parent and deleted
when the parent is deleted, minimized when the parent is minimized
etc. If supported by the window manager, it will also have a
common taskbar entry with its parent.
QDialog and QMainWindow widgets are by default top-level, even if
a parent widget is specified in the constructor. This behavior is
specified by the \c WType_TopLevel widget flag.
\sa topLevelWidget(), isDialog(), isModal(), isPopup(), isDesktop(), parentWidget()
*/
/*!
\property QWidget::isDialog
\brief whether the widget is a dialog widget
A dialog widget is a secondary top-level widget, i.e. a top-level
widget with a parent.
\sa isTopLevel(), QDialog
*/
/*!
\property QWidget::isPopup
\brief whether the widget is a popup widget
A popup widget is created by specifying the widget flag \c
WType_Popup to the widget constructor. A popup widget is also a
top-level widget.
\sa isTopLevel()
*/
/*!
\property QWidget::isDesktop
\brief whether the widget is a desktop widget, i.e. represents the desktop
A desktop widget is also a top-level widget.
\sa isTopLevel(), QApplication::desktop()
*/
/*!
\property QWidget::isModal
\brief whether the widget is a modal widget
This property only makes sense for top-level widgets. A modal
widget prevents widgets in all other top-level widgets from
getting any input.
\sa isTopLevel(), isDialog(), QDialog
*/
/*!
\property QWidget::underMouse
\brief whether the widget is under the mouse cursor
This value is not updated properly during drag and drop
operations.
\sa QEvent::Enter, QEvent::Leave
*/
/*!
\property QWidget::minimized
\brief whether this widget is minimized (iconified)
This property is only relevant for top-level widgets.
\sa showMinimized(), visible, show(), hide(), showNormal(), maximized
*/
bool QWidget::isMinimized() const
{ return testWState(WState_Minimized); }
/*!
Shows the widget minimized, as an icon.
Calling this function only affects \link isTopLevel() top-level
widgets\endlink.
\sa showNormal(), showMaximized(), show(), hide(), isVisible(),
isMinimized()
*/
void QWidget::showMinimized()
{
bool isMin = isMinimized();
if (isMin && isVisible()) return;
if (!isMin)
setWindowState((windowState() & ~WindowActive) | WindowMinimized);
show();
if (!isTopLevel())
QApplication::sendPostedEvents(this, QEvent::ShowMinimized);
}
/*!
\property QWidget::maximized
\brief whether this widget is maximized
This property is only relevant for top-level widgets.
Note that due to limitations in some window-systems, this does not
always report the expected results (e.g. if the user on X11
maximizes the window via the window manager, Qt has no way of
distinguishing this from any other resize). This is expected to
improve as window manager protocols evolve.
\sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized
*/
bool QWidget::isMaximized() const
{ return testWState(WState_Maximized); }
/*! Returns the current window state. The window state is a OR'ed
combination of Qt::WindowState: \c WindowMinimized, \c
WindowMaximized, \c WindowFullScreen and \c WindowActive.
\sa Qt::WindowState setWindowState()
*/
uint QWidget::windowState() const
{
uint state = 0;
if (testWState(WState_Minimized))
state |= WindowMinimized;
if (testWState(WState_Maximized))
state |= WindowMaximized;
if (testWState(WState_FullScreen))
state |= WindowFullScreen;
if (isActiveWindow())
state |= WindowActive;
return state;
}
/*!
\fn void QWidget::setWindowState(uint windowState)
Sets the window state to \a windowState. The window state is a OR'ed
combination of Qt::WindowState: \c WindowMinimized, \c
WindowMaximized, \c WindowFullScreen and \c WindowActive.
If the window is not visible (i.e. isVisible() returns FALSE), the
window state will take effect when show() is called. For visible
windows, the change is immediate. For example, to toggle between
full-screen and mormal mode, use the following code:
\code
w->setWindowState(w->windowState() ^ WindowFullScreen);
\endcode
In order to restore and activate a minimized window (while
preserving its maximized and/or full-screen state), use the following:
\code
w->setWindowState(w->windowState() & ~WindowMinimized | WindowActive);
\endcode
Note: On some window systems \c WindowActive is not immediate, and may be
ignored in certain cases.
\sa Qt::WindowState windowState()
*/
/*!
\property QWidget::fullScreen
\brief whether the widget is full screen
\sa windowState(), minimized, maximized
*/
bool QWidget::isFullScreen() const
{ return testWState(WState_FullScreen); }
/*!
Shows the widget in full-screen mode.
Calling this function only affects top-level widgets.
To return from full-screen mode, call showNormal().
Full-screen mode works fine under Windows, but has certain
problems under X. These problems are due to limitations of the
ICCCM protocol that specifies the communication between X11
clients and the window manager. ICCCM simply does not understand
the concept of non-decorated full-screen windows. Therefore, the
best we can do is to request a borderless window and place and
resize it to fill the entire screen. Depending on the window
manager, this may or may not work. The borderless window is
requested using MOTIF hints, which are at least partially
supported by virtually all modern window managers.
An alternative would be to bypass the window manager entirely and
create a window with the WX11BypassWM flag. This has other severe
problems though, like totally broken keyboard focus and very
strange effects on desktop changes or when the user raises other
windows.
X11 window managers that follow modern post-ICCCM specifications
support full-screen mode properly.
\sa showNormal(), showMaximized(), show(), hide(), isVisible()
*/
void QWidget::showFullScreen()
{
bool isFull = isFullScreen();
if (isFull && isVisible())
return;
if (!isFull)
setWindowState(windowState() | WindowFullScreen);
show();
if (!isTopLevel())
QApplication::sendPostedEvents(this, QEvent::ShowFullScreen);
setActiveWindow();
}
/*!
Shows the widget maximized.
Calling this function only affects \link isTopLevel() top-level
widgets\endlink.
On X11, this function may not work properly with certain window
managers. See the \link geometry.html Window Geometry
documentation\endlink for an explanation.
\sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()
*/
void QWidget::showMaximized()
{
if (isMaximized() && isVisible() && !isMinimized())
return;
setWindowState((windowState() & ~WindowMinimized) | WindowMaximized);
show();
if (!isTopLevel())
QApplication::sendPostedEvents(this, QEvent::ShowMaximized);
}
/*!
Restores the widget after it has been maximized or minimized.
Calling this function only affects \link isTopLevel() top-level
widgets\endlink.
\sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible()
*/
void QWidget::showNormal()
{
setWindowState(WindowNoState);
show();
if (!isTopLevel())
QApplication::sendPostedEvents(this, QEvent::ShowNormal);
}
/*!
Returns TRUE if this widget would become enabled if \a ancestor is
enabled; otherwise returns FALSE.
This is the case if neither the widget itself nor every parent up
to but excluding \a ancestor has been explicitly disabled.
isEnabledTo(0) is equivalent to isEnabled().
\sa setEnabled() enabled
*/
bool QWidget::isEnabledTo( QWidget* ancestor ) const
{
const QWidget * w = this;
while ( w && !w->testWState(WState_ForceDisabled)
&& !w->isTopLevel()
&& w->parentWidget()
&& w->parentWidget() != ancestor )
w = w->parentWidget();
return !w->testWState( WState_ForceDisabled );
}
/*!
\fn bool QWidget::isEnabledToTLW() const
\obsolete
This function is deprecated. It is equivalent to isEnabled()
*/
/*!
\property QWidget::enabled
\brief whether the widget is enabled
An enabled widget receives keyboard and mouse events; a disabled
widget does not. In fact, an enabled widget only receives keyboard
events when it is in focus.
Some widgets display themselves differently when they are
disabled. For example a button might draw its label grayed out. If
your widget needs to know when it becomes enabled or disabled, you
can reimplement the enabledChange() function.
Disabling a widget implicitly disables all its children. Enabling
respectively enables all child widgets unless they have been
explicitly disabled.
\sa isEnabled(), isEnabledTo(), QKeyEvent, QMouseEvent, enabledChange()
*/
void QWidget::setEnabled( bool enable )
{
if ( enable )
clearWState( WState_ForceDisabled );
else
setWState( WState_ForceDisabled );
if ( !isTopLevel() && parentWidget() &&
!parentWidget()->isEnabled() && enable )
return; // nothing we can do
if ( enable ) {
if ( testWState(WState_Disabled) ) {
clearWState( WState_Disabled );
setBackgroundFromMode();
enabledChange( !enable );
if ( children() ) {
QObjectListIt it( *children() );
QWidget *w;
while( (w = (QWidget *)it.current()) != 0 ) {
++it;
if ( w->isWidgetType() &&
!w->testWState( WState_ForceDisabled ) )
w->setEnabled( TRUE );
}
}
}
} else {
if ( !testWState(WState_Disabled) ) {
if (focusWidget() == this) {
bool parentIsEnabled = (!parentWidget() || parentWidget()->isEnabled());
if (!parentIsEnabled || !focusNextPrevChild(TRUE))
clearFocus();
}
setWState( WState_Disabled );
setBackgroundFromMode();
enabledChange( !enable );
if ( children() ) {
QObjectListIt it( *children() );
QWidget *w;
while( (w = (QWidget *)it.current()) != 0 ) {
++it;
if ( w->isWidgetType() && w->isEnabled() ) {
w->setEnabled( FALSE );
w->clearWState( WState_ForceDisabled );
}
}
}
}
}
#if defined(Q_WS_X11)
if ( testWState( WState_OwnCursor ) ) {
// enforce the windows behavior of clearing the cursor on
// disabled widgets
extern void qt_x11_enforce_cursor( QWidget * w ); // defined in qwidget_x11.cpp
qt_x11_enforce_cursor( this );
}
#endif
#ifdef Q_WS_WIN
QInputContext::enable( this, im_enabled & !((bool)testWState(WState_Disabled)) );
#endif
}
/*!
Disables widget input events if \a disable is TRUE; otherwise
enables input events.
See the \l enabled documentation for more information.
\sa isEnabledTo(), QKeyEvent, QMouseEvent, enabledChange()
*/
void QWidget::setDisabled( bool disable )
{
setEnabled( !disable );
}
/*!
\fn void QWidget::enabledChange( bool oldEnabled )
This virtual function is called from setEnabled(). \a oldEnabled
is the previous setting; you can get the new setting from
isEnabled().
Reimplement this function if your widget needs to know when it
becomes enabled or disabled. You will almost certainly need to
update the widget using update().
The default implementation repaints the visible part of the
widget.
\sa setEnabled(), isEnabled(), repaint(), update(), clipRegion()
*/
void QWidget::enabledChange( bool )
{
update();
#if defined(QT_ACCESSIBILITY_SUPPORT)
QAccessible::updateAccessibility( this, 0, QAccessible::StateChanged );
#endif
}
/*!
\fn void QWidget::windowActivationChange( bool oldActive )
This virtual function is called for a widget when its window is
activated or deactivated by the window system. \a oldActive is the
previous state; you can get the new setting from isActiveWindow().
Reimplement this function if your widget needs to know when its
window becomes activated or deactivated.
The default implementation updates the visible part of the widget
if the inactive and the active colorgroup are different for colors
other than the highlight and link colors.
\sa setActiveWindow(), isActiveWindow(), update(), palette()
*/
void QWidget::windowActivationChange( bool )
{
#ifndef QT_NO_PALETTE
if ( !isVisible() )
return;
const QColorGroup &acg = palette().active();
const QColorGroup &icg = palette().inactive();
if ( acg != icg ) {
BackgroundMode bm = backgroundMode();
QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode(bm);
if ( bm > NoBackground && acg.brush(role) != icg.brush(role) )
setBackgroundFromMode();
else if ( acg.background() == icg.background() &&
acg.base() == icg.base() &&
acg.text() == icg.text() &&
acg.foreground() == icg.foreground() &&
acg.button() == icg.button() &&
acg.buttonText() == icg.buttonText() &&
acg.brightText() == icg.brightText() &&
acg.dark() == icg.dark() &&
acg.light() == icg.light() &&
acg.mid() == icg.mid() &&
acg.midlight() == icg.midlight() &&
acg.shadow() == icg.shadow() )
return;
update();
}
#endif
}
/*!
\property QWidget::frameGeometry
\brief geometry of the widget relative to its parent including any
window frame
See the \link geometry.html Window Geometry documentation\endlink
for an overview of geometry issues with top-level widgets.
\sa geometry() x() y() pos()
*/
QRect QWidget::frameGeometry() const
{
if (isTopLevel() && ! isPopup()) {
if (fstrut_dirty)
updateFrameStrut();
QWidget *that = (QWidget *) this;
QTLWExtra *top = that->topData();
return QRect(crect.x() - top->fleft,
crect.y() - top->ftop,
crect.width() + top->fleft + top->fright,
crect.height() + top->ftop + top->fbottom);
}
return crect;
}
/*! \property QWidget::x
\brief the x coordinate of the widget relative to its parent including
any window frame
See the \link geometry.html Window Geometry documentation\endlink
for an overview of top-level widget geometry.
\sa frameGeometry, y, pos
*/
int QWidget::x() const
{
if (isTopLevel() && ! isPopup()) {
if (fstrut_dirty)
updateFrameStrut();
QWidget *that = (QWidget *) this;
return crect.x() - that->topData()->fleft;
}
return crect.x();
}
/*!
\property QWidget::y
\brief the y coordinate of the widget relative to its parent and
including any window frame
See the \link geometry.html Window Geometry documentation\endlink
for an overview of top-level widget geometry.
\sa frameGeometry, x, pos
*/
int QWidget::y() const
{
if (isTopLevel() && ! isPopup()) {
if (fstrut_dirty)
updateFrameStrut();
QWidget *that = (QWidget *) this;
return crect.y() - that->topData()->ftop;
}
return crect.y();
}
/*!
\property QWidget::pos
\brief the position of the widget within its parent widget
If the widget is a top-level widget, the position is that of the
widget on the desktop, including its frame.
When changing the position, the widget, if visible, receives a
move event (moveEvent()) immediately. If the widget is not
currently visible, it is guaranteed to receive an event before it
is shown.
move() is virtual, and all other overloaded move() implementations
in Qt call it.
\warning Calling move() or setGeometry() inside moveEvent() can
lead to infinite recursion.
See the \link geometry.html Window Geometry documentation\endlink
for an overview of top-level widget geometry.
\sa frameGeometry, size x(), y()
*/
QPoint QWidget::pos() const
{
if (isTopLevel() && ! isPopup()) {
if (fstrut_dirty)
updateFrameStrut();
QWidget *that = (QWidget *) this;
QTLWExtra *top = that->topData();
return QPoint(crect.x() - top->fleft, crect.y() - top->ftop);
}
return crect.topLeft();
}
/*!
\property QWidget::geometry
\brief the geometry of the widget relative to its parent and
excluding the window frame
When changing the geometry, the widget, if visible, receives a
move event (moveEvent()) and/or a resize event (resizeEvent())
immediately. If the widget is not currently visible, it is
guaranteed to receive appropriate events before it is shown.
The size component is adjusted if it lies outside the range
defined by minimumSize() and maximumSize().
setGeometry() is virtual, and all other overloaded setGeometry()
implementations in Qt call it.
\warning Calling setGeometry() inside resizeEvent() or moveEvent()
can lead to infinite recursion.
See the \link geometry.html Window Geometry documentation\endlink
for an overview of top-level widget geometry.
\sa frameGeometry(), rect(), move(), resize(), moveEvent(),
resizeEvent(), minimumSize(), maximumSize()
*/
/*!
\property QWidget::size
\brief the size of the widget excluding any window frame
When resizing, the widget, if visible, receives a resize event
(resizeEvent()) immediately. If the widget is not currently
visible, it is guaranteed to receive an event before it is shown.
The size is adjusted if it lies outside the range defined by
minimumSize() and maximumSize(). Furthermore, the size is always
at least QSize(1, 1). For toplevel widgets, the minimum size
might be larger, depending on the window manager.
If you want a top-level window to have a fixed size, call
setResizeMode( QLayout::FreeResize ) on its layout.
resize() is virtual, and all other overloaded resize()
implementations in Qt call it.
\warning Calling resize() or setGeometry() inside resizeEvent() can
lead to infinite recursion.
\sa pos, geometry, minimumSize, maximumSize, resizeEvent()
*/
/*!
\property QWidget::width
\brief the width of the widget excluding any window frame
See the \link geometry.html Window Geometry documentation\endlink
for an overview of top-level widget geometry.
\sa geometry, height, size
*/
/*!
\property QWidget::height
\brief the height of the widget excluding any window frame
See the \link geometry.html Window Geometry documentation\endlink
for an overview of top-level widget geometry.
\sa geometry, width, size
*/
/*!
\property QWidget::rect
\brief the internal geometry of the widget excluding any window
frame
The rect property equals QRect(0, 0, width(), height()).
See the \link geometry.html Window Geometry documentation\endlink
for an overview of top-level widget geometry.
\sa size
*/
/*!
\property QWidget::childrenRect
\brief the bounding rectangle of the widget's children
Hidden children are excluded.
\sa childrenRegion() geometry()
*/
QRect QWidget::childrenRect() const
{
QRect r( 0, 0, 0, 0 );
if ( !children() )
return r;
QObjectListIt it( *children() );
QObject *obj;
while ( (obj = it.current()) ) {
++it;
if ( obj->isWidgetType() && !((QWidget*)obj)->isHidden() && !((QWidget*)obj)->isTopLevel())
r = r.unite( ((QWidget*)obj)->geometry() );
}
return r;
}
/*!
\property QWidget::childrenRegion
\brief the combined region occupied by the widget's children
Hidden children are excluded.
\sa childrenRect() geometry()
*/
QRegion QWidget::childrenRegion() const
{
QRegion r;
if ( !children() )
return r;
QObjectListIt it( *children() ); // iterate over all children
QObject *obj;
while ( (obj=it.current()) ) {
++it;
if ( obj->isWidgetType() && !((QWidget*)obj)->isHidden() && !((QWidget*)obj)->isTopLevel())
r = r.unite( ((QWidget*)obj)->geometry() );
}
return r;
}
/*!
\property QWidget::minimumSize
\brief the widget's minimum size
The widget cannot be resized to a smaller size than the minimum
widget size. The widget's size is forced to the minimum size if
the current size is smaller.
If you use a layout inside the widget, the minimum size will be
set by the layout and not by setMinimumSize(), unless you set the
layout's resize mode to QLayout::FreeResize.
\sa minimumWidth, minimumHeight, maximumSize, sizeIncrement
QLayout::setResizeMode()
*/
QSize QWidget::minimumSize() const
{
return extra ? QSize( extra->minw, extra->minh ) : QSize( 0, 0 );
}
/*!
\property QWidget::maximumSize
\brief the widget's maximum size
The widget cannot be resized to a larger size than the maximum
widget size.
\sa maximumWidth(), maximumHeight(), setMaximumSize(),
minimumSize(), sizeIncrement()
*/
QSize QWidget::maximumSize() const
{
return extra ? QSize( extra->maxw, extra->maxh )
: QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
}
/*!
\property QWidget::minimumWidth
\brief the widget's minimum width
This property corresponds to minimumSize().width().
\sa minimumSize, minimumHeight
*/
/*!
\property QWidget::minimumHeight
\brief the widget's minimum height
This property corresponds to minimumSize().height().
\sa minimumSize, minimumWidth
*/
/*!
\property QWidget::maximumWidth
\brief the widget's maximum width
This property corresponds to maximumSize().width().
\sa maximumSize, maximumHeight
*/
/*!
\property QWidget::maximumHeight
\brief the widget's maximum height
This property corresponds to maximumSize().height().
\sa maximumSize, maximumWidth
*/
/*!
\property QWidget::sizeIncrement
\brief the size increment of the widget
When the user resizes the window, the size will move in steps of
sizeIncrement().width() pixels horizontally and
sizeIncrement.height() pixels vertically, with baseSize() as the
basis. Preferred widget sizes are for non-negative integers \e i
and \e j:
\code
width = baseSize().width() + i * sizeIncrement().width();
height = baseSize().height() + j * sizeIncrement().height();
\endcode
Note that while you can set the size increment for all widgets, it
only affects top-level widgets.
\warning The size increment has no effect under Windows, and may
be disregarded by the window manager on X.
\sa size, minimumSize, maximumSize
*/
QSize QWidget::sizeIncrement() const
{
return ( extra && extra->topextra )
? QSize( extra->topextra->incw, extra->topextra->inch )
: QSize( 0, 0 );
}
/*!
\property QWidget::baseSize
\brief the base size of the widget
The base size is used to calculate a proper widget size if the
widget defines sizeIncrement().
\sa setSizeIncrement()
*/
QSize QWidget::baseSize() const
{
return ( extra != 0 && extra->topextra != 0 )
? QSize( extra->topextra->basew, extra->topextra->baseh )
: QSize( 0, 0 );
}
/*!
Sets both the minimum and maximum sizes of the widget to \a s,
thereby preventing it from ever growing or shrinking.
\sa setMaximumSize() setMinimumSize()
*/
void QWidget::setFixedSize( const QSize & s)
{
setMinimumSize( s );
setMaximumSize( s );
resize( s );
}
/*!
\overload void QWidget::setFixedSize( int w, int h )
Sets the width of the widget to \a w and the height to \a h.
*/
void QWidget::setFixedSize( int w, int h )
{
setMinimumSize( w, h );
setMaximumSize( w, h );
resize( w, h );
}
void QWidget::setMinimumWidth( int w )
{
setMinimumSize( w, minimumSize().height() );
}
void QWidget::setMinimumHeight( int h )
{
setMinimumSize( minimumSize().width(), h );
}
void QWidget::setMaximumWidth( int w )
{
setMaximumSize( w, maximumSize().height() );
}
void QWidget::setMaximumHeight( int h )
{
setMaximumSize( maximumSize().width(), h );
}
/*!
Sets both the minimum and maximum width of the widget to \a w
without changing the heights. Provided for convenience.
\sa sizeHint() minimumSize() maximumSize() setFixedSize()
*/
void QWidget::setFixedWidth( int w )
{
setMinimumSize( w, minimumSize().height() );
setMaximumSize( w, maximumSize().height() );
}
/*!
Sets both the minimum and maximum heights of the widget to \a h
without changing the widths. Provided for convenience.
\sa sizeHint() minimumSize() maximumSize() setFixedSize()
*/
void QWidget::setFixedHeight( int h )
{
setMinimumSize( minimumSize().width(), h );
setMaximumSize( maximumSize().width(), h );
}
/*!
Translates the widget coordinate \a pos to the coordinate system
of \a parent. The \a parent must not be 0 and must be a parent
of the calling widget.
\sa mapFrom() mapToParent() mapToGlobal() hasMouse()
*/
QPoint QWidget::mapTo( QWidget * parent, const QPoint & pos ) const
{
QPoint p = pos;
if ( parent ) {
const QWidget * w = this;
while ( w != parent ) {
p = w->mapToParent( p );
w = w->parentWidget();
}
}
return p;
}
/*!
Translates the widget coordinate \a pos from the coordinate system
of \a parent to this widget's coordinate system. The \a parent
must not be 0 and must be a parent of the calling widget.
\sa mapTo() mapFromParent() mapFromGlobal() hasMouse()
*/
QPoint QWidget::mapFrom( QWidget * parent, const QPoint & pos ) const
{
QPoint p( pos );
if ( parent ) {
const QWidget * w = this;
while ( w != parent ) {
p = w->mapFromParent( p );
w = w->parentWidget();
}
}
return p;
}
/*!
Translates the widget coordinate \a pos to a coordinate in the
parent widget.
Same as mapToGlobal() if the widget has no parent.
\sa mapFromParent() mapTo() mapToGlobal() hasMouse()
*/
QPoint QWidget::mapToParent( const QPoint &pos ) const
{
return pos + crect.topLeft();
}
/*!
Translates the parent widget coordinate \a pos to widget
coordinates.
Same as mapFromGlobal() if the widget has no parent.
\sa mapToParent() mapFrom() mapFromGlobal() hasMouse()
*/
QPoint QWidget::mapFromParent( const QPoint &pos ) const
{
return pos - crect.topLeft();
}
/*!
Returns the top-level widget for this widget, i.e. the next
ancestor widget that has (or could have) a window-system frame.
If the widget is a top-level, the widget itself is returned.
Typical usage is changing the window caption:
\code
aWidget->topLevelWidget()->setCaption( "New Caption" );
\endcode
\sa isTopLevel()
*/
QWidget *QWidget::topLevelWidget() const
{
QWidget *w = (QWidget *)this;
QWidget *p = w->parentWidget();
while ( !w->testWFlags(WType_TopLevel) && p ) {
w = p;
p = p->parentWidget();
}
return w;
}
/*!
\property QWidget::paletteForegroundColor
\brief the foreground color of the widget
setPaletteForegroundColor() is a convenience function that creates
and sets a modified QPalette with setPalette(). The palette is
modified according to the widget's \e {background mode}. For
example, if the background mode is \c PaletteButton the palette entry
\c QColorGroup::ButtonText is set to color.
\sa setPalette() QApplication::setPalette() backgroundMode()
foregroundColor() setBackgroundMode() setEraseColor()
*/
const QColor &QWidget::paletteForegroundColor() const
{
#ifndef QT_NO_PALETTE
BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
return colorGroup().color( QPalette::foregroundRoleFromMode(mode) );
#else
return Qt::black;
#endif
}
void QWidget::setPaletteForegroundColor( const QColor & color )
{
#ifndef QT_NO_PALETTE
BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
QPalette pal = palette();
QColorGroup::ColorRole role = QPalette::foregroundRoleFromMode( mode );
pal.setColor( QPalette::Active, role, color );
pal.setColor( QPalette::Inactive, role, color );
pal.setColor( QPalette::Disabled, role, color );
setPalette( pal );
#endif
}
/*!
Same as paletteForegroundColor()
*/
const QColor &QWidget::foregroundColor() const
{
return paletteForegroundColor();
}
/*!
\fn const QColor& QWidget::eraseColor() const
Returns the erase color of the widget.
\sa setEraseColor() setErasePixmap() backgroundColor()
*/
/*!
Sets the erase color of the widget to \a color.
The erase color is the color the widget is to be cleared to before
paintEvent() is called. If there is an erase pixmap (set using
setErasePixmap()), then this property has an indeterminate value.
\sa erasePixmap(), backgroundColor(), backgroundMode(), palette()
*/
void QWidget::setEraseColor( const QColor & color )
{
setBackgroundModeDirect( FixedColor );
setBackgroundColorDirect( color );
update();
}
/*!
Returns the widget's erase pixmap.
\sa setErasePixmap() eraseColor()
*/
const QPixmap *QWidget::erasePixmap() const
{
return ( extra && extra->bg_pix ) ? extra->bg_pix : 0;
}
/*!
Sets the widget's erase pixmap to \a pixmap.
This pixmap is used to clear the widget before paintEvent() is
called.
*/
void QWidget::setErasePixmap( const QPixmap &pixmap )
{
// This function is called with a null pixmap by setBackgroundEmpty().
setBackgroundPixmapDirect( pixmap );
setBackgroundModeDirect( FixedPixmap );
update();
}
void QWidget::setBackgroundFromMode()
{
#ifndef QT_NO_PALETTE
QColorGroup::ColorRole r = QColorGroup::Background;
if ( extra ) {
int i = (BackgroundMode)extra->bg_mode;
if ( i == FixedColor || i == FixedPixmap || i == NoBackground ) {
// Mode is for fixed color, not one based on palette,
// so nothing to do.
return;
}
switch( i ) {
case PaletteForeground:
r = QColorGroup::Foreground;
break;
case PaletteButton:
r = QColorGroup::Button;
break;
case PaletteLight:
r = QColorGroup::Light;
break;
case PaletteMidlight:
r = QColorGroup::Midlight;
break;
case PaletteDark:
r = QColorGroup::Dark;
break;
case PaletteMid:
r = QColorGroup::Mid;
break;
case PaletteText:
r = QColorGroup::Text;
break;
case PaletteBrightText:
r = QColorGroup::BrightText;
break;
case PaletteBase:
r = QColorGroup::Base;
break;
case PaletteBackground:
r = QColorGroup::Background;
break;
case PaletteShadow:
r = QColorGroup::Shadow;
break;
case PaletteHighlight:
r = QColorGroup::Highlight;
break;
case PaletteHighlightedText:
r = QColorGroup::HighlightedText;
break;
case PaletteButtonText:
r = QColorGroup::ButtonText;
break;
case X11ParentRelative:
#if defined(Q_WS_X11)
setBackgroundX11Relative();
#endif
return;
}
}
const QColorGroup &cg = colorGroup();
QPixmap * p = cg.brush( r ).pixmap();
if ( p )
setBackgroundPixmapDirect( *p );
else
setBackgroundColorDirect( cg.color( r ) );
#endif
}
/*!
\enum Qt::BackgroundMode
This enum describes how the background of a widget changes, as the
widget's palette changes.
The background is what the widget contains when \link
QWidget::paintEvent() paintEvent()\endlink is called. To minimize
flicker, this should be the most common color or pixmap in the
widget. For \c PaletteBackground, use colorGroup().brush( \c
QColorGroup::Background ), and so on.
\value PaletteForeground
\value PaletteBackground
\value PaletteButton
\value PaletteLight
\value PaletteMidlight
\value PaletteDark
\value PaletteMid
\value PaletteText
\value PaletteBrightText
\value PaletteButtonText
\value PaletteBase
\value PaletteShadow
\value PaletteHighlight
\value PaletteHighlightedText
\value PaletteLink
\value PaletteLinkVisited
\value X11ParentRelative (internal use only)
The final three values have special meaning:
\value NoBackground the widget is not cleared before paintEvent().
If the widget's paint event always draws on all the pixels, using
this mode can be both fast and flicker-free.
\value FixedColor the widget is cleared to a fixed color, normally
different from all the ones in the palette(). Set using \link
QWidget::setPaletteBackgroundColor()
setPaletteBackgroundColor()\endlink.
\value FixedPixmap the widget is cleared to a fixed pixmap,
normally different from all the ones in the palette(). Set using
\link QWidget::setPaletteBackgroundPixmap()
setPaletteBackgroundPixmap()\endlink.
Although \c FixedColor and \c FixedPixmap are sometimes just
right, if you use them, make sure that you test your application
when the desktop color scheme has been changed. (On X11, a quick
way to test this is e.g. "./myapp -bg paleblue". On Windows, you
must use the control panel.)
\sa QWidget::setBackgroundMode() QWidget::backgroundMode()
QWidget::setBackgroundPixmap() QWidget::setPaletteBackgroundColor()
*/
/*!
\property QWidget::backgroundMode
\brief the color role used for painting the background of the widget
setPaletteBackgroundColor() reads this property to determine which
entry of the \link QWidget::palette palette\endlink to set.
For most widgets the default suffices (\c PaletteBackground,
typically gray), but some need to use \c PaletteBase (the
background color for text output, typically white) or another
role.
QListBox, which is "sunken" and uses the base color to contrast
with its environment, does this in its constructor:
\code
setBackgroundMode( PaletteBase );
\endcode
You will never need to set the background mode of a built-in
widget in Qt, but you might consider setting it in your custom
widgets, so that setPaletteBackgroundColor() works as expected.
Note that two of the BackgroundMode values make no sense for
setBackgroundMode(), namely \c FixedPixmap and \c FixedColor. You
must call setBackgroundPixmap() and setPaletteBackgroundColor()
instead.
*/
Qt::BackgroundMode QWidget::backgroundMode() const
{
return extra ? (BackgroundMode) extra->bg_mode : PaletteBackground;
}
void QWidget::setBackgroundMode( BackgroundMode m )
{
setBackgroundMode( m, m );
if ( (widget_state & (WState_Visible|WState_BlockUpdates)) ==
WState_Visible )
update();
}
/*!
\overload
Sets the widget's own background mode to \a m and the visual
background mode to \a visual. The visual background mode is used
with the designable properties \c backgroundColor, \c
foregroundColor and \c backgroundPixmap.
For complex controls, the logical background mode sometimes
differs from a widget's own background mode. A spinbox for example
has \c PaletteBackground as background mode (typically dark gray),
while it's embedded lineedit control uses \c PaletteBase
(typically white). Since the lineedit covers most of the visual
area of a spinbox, it defines \c PaletteBase to be its \a visual
background mode. Changing the \c backgroundColor property thus
changes the lineedit control's background, which is exactly what
the user expects in \e{Qt Designer}.
*/
void QWidget::setBackgroundMode( BackgroundMode m, BackgroundMode visual )
{
if ( m == NoBackground ) {
setBackgroundEmpty();
} else if ( m == FixedColor || m == FixedPixmap ) {
#if defined(QT_DEBUG)
qWarning( "QWidget::setBackgroundMode: FixedColor or FixedPixmap makes"
" no sense" );
#endif
return;
}
setBackgroundModeDirect(m);
if ( m != visual && !extra )
createExtra();
if ( extra )
extra->bg_mode_visual = visual;
}
/*!
\internal
*/
void QWidget::setBackgroundModeDirect( BackgroundMode m )
{
if ( m == PaletteBackground && !extra )
return;
createExtra();
if ( (BackgroundMode)extra->bg_mode != m ) {
extra->bg_mode = m;
extra->bg_mode_visual = m;
setBackgroundFromMode();
}
}
/*!
\property QWidget::paletteBackgroundColor
\brief the background color of the widget
The palette background color is usually set implicitly by
setBackgroundMode(), although it can also be set explicitly by
setPaletteBackgroundColor(). setPaletteBackgroundColor() is a
convenience function that creates and sets a modified QPalette
with setPalette(). The palette is modified according to the
widget's background mode. For example, if the background mode is
\c PaletteButton the color used for the palette's \c
QColorGroup::Button color entry is set.
If there is a background pixmap (set using
setPaletteBackgroundPixmap()), then the return value of this
function is indeterminate.
\sa paletteBackgroundPixmap, paletteForegroundColor, palette, colorGroup()
*/
const QColor & QWidget::paletteBackgroundColor() const
{
#ifndef QT_NO_PALETTE
BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
switch( mode ) {
case FixedColor:
case FixedPixmap :
case NoBackground:
case X11ParentRelative:
return eraseColor();
default:
QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
return colorGroup().color( role );
}
#else
return eraseColor();
#endif
}
void QWidget::setPaletteBackgroundColor( const QColor &color )
{
#ifndef QT_NO_PALETTE
BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
switch( mode ) {
case FixedColor:
case FixedPixmap :
case NoBackground:
case X11ParentRelative:
setEraseColor( color );
break;
default:
QPalette pal = palette();
QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
pal.setColor( QPalette::Active, role, color );
pal.setColor( QPalette::Inactive, role, color );
pal.setColor( QPalette::Disabled, role, color );
setPalette( pal );
break;
}
#else
setEraseColor( color );
#endif
}
/*!
\property QWidget::paletteBackgroundPixmap
\brief the background pixmap of the widget
The palette background pixmap is usually set implicitly by
setBackgroundMode(), although it can also be set explicitly by
setPaletteBackgroundPixmap(). setPaletteBackgroundPixmap() is a
convenience function that creates and sets a modified QPalette
with setPalette(). The palette is modified according to the
widget's background mode. For example, if the background mode is
\c PaletteButton the pixmap used for the palette's
\c QColorGroup::Button color entry is set.
If there is a plain background color (set using
setPaletteBackgroundColor()), then this function returns 0.
\sa paletteBackgroundColor, paletteForegroundColor, palette, colorGroup()
*/
const QPixmap *QWidget::paletteBackgroundPixmap() const
{
#ifndef QT_NO_PALETTE
BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
switch( mode ) {
case FixedColor:
case FixedPixmap :
case NoBackground:
case X11ParentRelative:
return erasePixmap();
default:
QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
return palette().brush( QPalette::Active, role ).pixmap();
}
#else
return erasePixmap();
#endif
}
void QWidget::setPaletteBackgroundPixmap( const QPixmap &pixmap )
{
#ifndef QT_NO_PALETTE
BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
switch( mode ) {
case FixedColor:
case FixedPixmap :
case NoBackground:
case X11ParentRelative:
setErasePixmap( pixmap );
break;
default:
QPalette pal = palette();
QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
pal.setBrush( QPalette::Active, role, QBrush( pal.color( QPalette::Active, role ), pixmap ) );
pal.setBrush( QPalette::Inactive, role, QBrush( pal.color( QPalette::Inactive, role ), pixmap ) );
pal.setBrush( QPalette::Disabled, role, QBrush( pal.color( QPalette::Disabled, role ), pixmap ) );
setPalette( pal );
break;
}
#else
setErasePixmap( pixmap );
#endif
}
/*!
\property QWidget::backgroundBrush
\brief the widget's background brush
The background brush depends on a widget's palette and its
background mode.
\sa backgroundColor(), backgroundPixmap(), eraseColor(), palette,
QApplication::setPalette()
*/
const QBrush& QWidget::backgroundBrush() const
{
static QBrush noBrush;
#ifndef QT_NO_PALETTE
BackgroundMode mode = extra ? (BackgroundMode) extra->bg_mode_visual : PaletteBackground;
switch( mode ) {
case FixedColor:
case FixedPixmap :
case NoBackground:
case X11ParentRelative:
return noBrush;
default:
QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
return colorGroup().brush( role );
}
#else
return noBrush;
#endif
}
/*!
\property QWidget::colorGroup
\brief the current color group of the widget palette
The color group is determined by the state of the widget. A
disabled widget has the QPalette::disabled() color group, a widget
with keyboard focus has the QPalette::active() color group, and an
inactive widget has the QPalette::inactive() color group.
\sa palette
*/
#ifndef QT_NO_PALETTE
const QColorGroup &QWidget::colorGroup() const
{
if ( !isEnabled() )
return palette().disabled();
else if ( !isVisible() || isActiveWindow() )
return palette().active();
else
return palette().inactive();
}
#endif
/*!
\property QWidget::palette
\brief the widget's palette
As long as no special palette has been set, or after unsetPalette()
has been called, this is either a special palette for the widget
class, the parent's palette or (if this widget is a top level
widget), the default application palette.
Instead of defining an entirely new palette, you can also use the
\link QWidget::paletteBackgroundColor paletteBackgroundColor\endlink,
\link QWidget::paletteBackgroundPixmap paletteBackgroundPixmap\endlink and
\link QWidget::paletteForegroundColor paletteForegroundColor\endlink
convenience properties to change a widget's
background and foreground appearance only.
\sa ownPalette, colorGroup(), QApplication::palette()
*/
#ifndef QT_NO_PALETTE
void QWidget::setPalette( const QPalette &palette )
{
own_palette = TRUE;
if ( pal == palette )
return;
QPalette old = pal;
pal = palette;
setBackgroundFromMode();
QEvent ev( QEvent::PaletteChange );
QApplication::sendEvent( this, &ev );
if ( children() ) {
QEvent e( QEvent::ParentPaletteChange );
QObjectListIt it( *children() );
QWidget *w;
while( (w=(QWidget *)it.current()) != 0 ) {
++it;
if ( w->isWidgetType() )
QApplication::sendEvent( w, &e );
}
}
paletteChange( old );
update();
}
void QWidget::unsetPalette()
{
// reset the palette
setPalette( qt_naturalWidgetPalette( this ) );
own_palette = FALSE;
}
/*!
\fn void QWidget::setPalette( const QPalette&, bool )
\obsolete
Use setPalette( const QPalette& p ) instead.
*/
/*!
\fn void QWidget::paletteChange( const QPalette &oldPalette )
This virtual function is called from setPalette(). \a oldPalette
is the previous palette; you can get the new palette from
palette().
Reimplement this function if your widget needs to know when its
palette changes.
\sa setPalette(), palette()
*/
void QWidget::paletteChange( const QPalette & )
{
}
#endif // QT_NO_PALETTE
/*!
\property QWidget::font
\brief the font currently set for the widget
The fontInfo() function reports the actual font that is being used
by the widget.
As long as no special font has been set, or after unsetFont() is
called, this is either a special font for the widget class, the
parent's font or (if this widget is a top level widget), the
default application font.
This code fragment sets a 12 point helvetica bold font:
\code
QFont f( "Helvetica", 12, QFont::Bold );
setFont( f );
\endcode
In addition to setting the font, setFont() informs all children
about the change.
\sa fontChange() fontInfo() fontMetrics() ownFont()
*/
void QWidget::setFont( const QFont &font )
{
own_font = TRUE;
if ( fnt == font && fnt.d->mask == font.d->mask )
return;
QFont old = fnt;
fnt = font.resolve( qt_naturalWidgetFont( this ) );
#if defined(Q_WS_X11)
// make sure the font set on this widget is associated with the correct screen
fnt.x11SetScreen( x11Screen() );
#endif
if ( children() ) {
QEvent e( QEvent::ParentFontChange );
QObjectListIt it( *children() );
QWidget *w;
while( (w=(QWidget *)it.current()) != 0 ) {
++it;
if ( w->isWidgetType() )
QApplication::sendEvent( w, &e );
}
}
if ( hasFocus() )
setFontSys();
fontChange( old );
}
void QWidget::unsetFont()
{
// reset the font
setFont( qt_naturalWidgetFont( this ) );
own_font = FALSE;
}
/*!
\fn void QWidget::setFont( const QFont&, bool )
\obsolete
Use setFont(const QFont& font) instead.
*/
/*!
\fn void QWidget::fontChange( const QFont &oldFont )
This virtual function is called from setFont(). \a oldFont is the
previous font; you can get the new font from font().
Reimplement this function if your widget needs to know when its
font changes. You will almost certainly need to update the widget
using update().
The default implementation updates the widget including its
geometry.
\sa setFont(), font(), update(), updateGeometry()
*/
void QWidget::fontChange( const QFont & )
{
update();
updateGeometry();
}
/*!
\fn QFontMetrics QWidget::fontMetrics() const
Returns the font metrics for the widget's current font.
Equivalent to QFontMetrics(widget->font()).
\sa font(), fontInfo(), setFont()
*/
/*!
\fn QFontInfo QWidget::fontInfo() const
Returns the font info for the widget's current font.
Equivalent to QFontInto(widget->font()).
\sa font(), fontMetrics(), setFont()
*/
/*!
\property QWidget::cursor
\brief the cursor shape for this widget
The mouse cursor will assume this shape when it's over this
widget. See the \link Qt::CursorShape list of predefined cursor
objects\endlink for a range of useful shapes.
An editor widget might use an I-beam cursor:
\code
setCursor( IbeamCursor );
\endcode
If no cursor has been set, or after a call to unsetCursor(), the
parent's cursor is used. The function unsetCursor() has no effect
on top-level widgets.
\sa QApplication::setOverrideCursor()
*/
#ifndef QT_NO_CURSOR
const QCursor &QWidget::cursor() const
{
if ( testWState(WState_OwnCursor) )
return (extra && extra->curs)
? *extra->curs
: arrowCursor;
else
return (isTopLevel() || !parentWidget()) ? arrowCursor : parentWidget()->cursor();
}
#endif
#ifndef QT_NO_WIDGET_TOPEXTRA
/*!
\property QWidget::caption
\brief the window caption (title)
This property only makes sense for top-level widgets. If no
caption has been set, the caption is QString::null.
\sa icon() iconText()
*/
QString QWidget::caption() const
{
return extra && extra->topextra
? extra->topextra->caption
: QString::null;
}
/*!
\property QWidget::icon
\brief the widget's icon
This property only makes sense for top-level widgets. If no icon
has been set, icon() returns 0.
\sa iconText, caption,
\link appicon.html Setting the Application Icon\endlink
*/
const QPixmap *QWidget::icon() const
{
return ( extra && extra->topextra ) ? extra->topextra->icon : 0;
}
/*!
\property QWidget::iconText
\brief the widget's icon text
This property only makes sense for top-level widgets. If no icon
text has been set, this functions returns QString::null.
\sa icon, caption
*/
QString QWidget::iconText() const
{
return ( extra && extra->topextra ) ? extra->topextra->iconText
: QString::null;
}
#endif //QT_NO_WIDGET_TOPEXTRA
/*!
\property QWidget::mouseTracking
\brief whether mouse tracking is enabled for the widget
If mouse tracking is disabled (the default), the widget only
receives mouse move events when at least one mouse button is
pressed while the mouse is being moved.
If mouse tracking is enabled, the widget receives mouse move
events even if no buttons are pressed.
\sa mouseMoveEvent(), QApplication::setGlobalMouseTracking()
*/
/*!
Sets the widget's focus proxy to widget \a w. If \a w is 0, the
function resets this widget to have no focus proxy.
Some widgets, such as QComboBox, can "have focus", but create a
child widget to actually handle the focus. QComboBox, for example,
creates a QLineEdit which handles the focus.
setFocusProxy() sets the widget which will actually get focus when
"this widget" gets it. If there is a focus proxy, focusPolicy(),
setFocusPolicy(), setFocus() and hasFocus() all operate on the
focus proxy.
\sa focusProxy()
*/
void QWidget::setFocusProxy( QWidget * w )
{
if ( !w && !extra )
return;
for ( QWidget* fp = w; fp; fp = fp->focusProxy() ) {
if ( fp == this ) {
#if defined (QT_CHECK_STATE)
qWarning( "%s (%s): already in focus proxy chain", className(), name() );
#endif
return;
}
}
createExtra();
if ( extra->focus_proxy ) {
disconnect( extra->focus_proxy, SIGNAL(destroyed()),
this, SLOT(focusProxyDestroyed()) );
extra->focus_proxy = 0;
}
if ( w ) {
setFocusPolicy( w->focusPolicy() );
connect( w, SIGNAL(destroyed()),
this, SLOT(focusProxyDestroyed()) );
}
extra->focus_proxy = w;
}
/*!
Returns the focus proxy, or 0 if there is no focus proxy.
\sa setFocusProxy()
*/
QWidget * QWidget::focusProxy() const
{
return extra ? extra->focus_proxy : 0;
}
/*!
\internal
Internal slot used to clean up if the focus proxy is destroyed.
\sa setFocusProxy()
*/
void QWidget::focusProxyDestroyed()
{
if ( extra )
extra->focus_proxy = 0;
setFocusPolicy( NoFocus );
}
/*!
\property QWidget::focus
\brief whether this widget (or its focus proxy) has the keyboard
input focus
Effectively equivalent to \c {qApp->focusWidget() == this}.
\sa setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget()
*/
bool QWidget::hasFocus() const
{
const QWidget* w = this;
while ( w->focusProxy() )
w = w->focusProxy();
return qApp->focusWidget() == w;
}
/*!
Gives the keyboard input focus to this widget (or its focus
proxy) if this widget or one of its parents is the \link
isActiveWindow() active window\endlink.
First, a focus out event is sent to the focus widget (if any) to
tell it that it is about to lose the focus. Then a focus in event
is sent to this widget to tell it that it just received the focus.
(Nothing happens if the focus in and focus out widgets are the
same.)
setFocus() gives focus to a widget regardless of its focus policy,
but does not clear any keyboard grab (see grabKeyboard()).
Be aware that if the widget is hidden, it will not accept focus.
\warning If you call setFocus() in a function which may itself be
called from focusOutEvent() or focusInEvent(), you may get an
infinite recursion.
\sa hasFocus() clearFocus() focusInEvent() focusOutEvent()
setFocusPolicy() QApplication::focusWidget() grabKeyboard()
grabMouse()
*/
void QWidget::setFocus()
{
if ( !isEnabled() )
return;
if ( focusProxy() ) {
focusProxy()->setFocus();
return;
}
QFocusData * f = focusData( TRUE );
if ( f->it.current() == this && qApp->focusWidget() == this
#if defined(Q_WS_WIN)
&& GetFocus() == winId()
#endif
)
return;
f->it.toFirst();
while ( f->it.current() != this && !f->it.atLast() )
++f->it;
// at this point, the iterator should point to 'this'. if it
// does not, 'this' must not be in the list - an error, but
// perhaps possible. fix it.
if ( f->it.current() != this ) {
f->focusWidgets.append( this );
f->it.toLast();
}
if ( isActiveWindow() ) {
QWidget * prev = qApp->focus_widget;
if ( prev ) {
// This part is never executed when Q_WS_X11? Preceding XFocusOut
// had already reset focus_widget when received XFocusIn
// Don't reset input context explicitly here. Whether reset or not
// when focusing out is a responsibility of input methods. For
// example, Japanese input context should not be reset here. The
// context sometimes contains a whole paragraph and has minutes of
// lifetime different to ephemeral one in other languages. The
// input context should be survived until focused again. So we
// delegate the responsibility to input context via
// unfocusInputContext().
if ( prev != this && prev->isInputMethodEnabled() ) {
#if 0
prev->resetInputContext();
#else
prev->unfocusInputContext();
#endif
}
}
#if defined(Q_WS_WIN)
else {
QInputContext::endComposition();
}
#endif
qApp->focus_widget = this;
if( isInputMethodEnabled() )
focusInputContext();
#if defined(Q_WS_WIN)
if ( !topLevelWidget()->isPopup() )
SetFocus( winId() );
else {
#endif
#if defined(QT_ACCESSIBILITY_SUPPORT)
QAccessible::updateAccessibility( this, 0, QAccessible::Focus );
#endif
#if defined(Q_WS_WIN)
}
#endif
if ( prev != this ) {
if ( prev ) {
QFocusEvent out( QEvent::FocusOut );
QApplication::sendEvent( prev, &out );
}
if ( qApp->focus_widget == this ) {
QFocusEvent in( QEvent::FocusIn );
QApplication::sendEvent( this, &in );
}
}
}
}
/*!
Takes keyboard input focus from the widget.
If the widget has active focus, a \link focusOutEvent() focus out
event\endlink is sent to this widget to tell it that it is about
to lose the focus.
This widget must enable focus setting in order to get the keyboard
input focus, i.e. it must call setFocusPolicy().
\sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(),
setFocusPolicy(), QApplication::focusWidget()
*/
void QWidget::clearFocus()
{
if ( focusProxy() ) {
focusProxy()->clearFocus();
return;
} else if ( hasFocus() ) {
#if !defined(Q_WS_X11)
resetInputContext();
#else
unfocusInputContext();
#endif
QWidget* w = qApp->focusWidget();
// clear active focus
qApp->focus_widget = 0;
QFocusEvent out( QEvent::FocusOut );
QApplication::sendEvent( w, &out );
#if defined(Q_WS_WIN)
if ( !isPopup() && GetFocus() == winId() )
SetFocus( 0 );
else {
#endif
#if defined(QT_ACCESSIBILITY_SUPPORT)
QAccessible::updateAccessibility( this, 0, QAccessible::Focus );
#endif
#if defined(Q_WS_WIN)
}
#endif
}
}
/*!
Finds a new widget to give the keyboard focus to, as appropriate
for Tab and Shift+Tab, and returns TRUE if is can find a new
widget and FALSE if it can't,
If \a next is TRUE, this function searches "forwards", if \a next
is FALSE, it searches "backwards".
Sometimes, you will want to reimplement this function. For
example, a web browser might reimplement it to move its "current
active link" forwards or backwards, and call
QWidget::focusNextPrevChild() only when it reaches the last or
first link on the "page".
Child widgets call focusNextPrevChild() on their parent widgets,
but only the top-level widget decides where to redirect focus. By
overriding this method for an object, you thus gain control of
focus traversal for all child widgets.
\warning QScrollView uses it own logic for this function, which
does the right thing in most cases. But if you are using a
QScrollView and want complete control of the focus chain you'll
need to override QScrollView::focusNextPrevChild() and your
top-level widgets' focusNextPrevChild() functions.
\sa focusData()
*/
bool QWidget::focusNextPrevChild( bool next )
{
QWidget* p = parentWidget();
if ( !isTopLevel() && p )
return p->focusNextPrevChild(next);
QFocusData *f = focusData( TRUE );
QWidget *startingPoint = f->it.current();
QWidget *candidate = 0;
QWidget *w = next ? f->focusWidgets.last() : f->focusWidgets.first();
extern bool qt_tab_all_widgets;
uint focus_flag = qt_tab_all_widgets ? TabFocus : StrongFocus;
do {
if ( w && w != startingPoint &&
( ( w->focusPolicy() & focus_flag ) == focus_flag )
&& !w->focusProxy() && w->isVisibleTo(this) && w->isEnabled())
candidate = w;
w = next ? f->focusWidgets.prev() : f->focusWidgets.next();
} while( w && !(candidate && w==startingPoint) );
if ( !candidate )
return FALSE;
candidate->setFocus();
return TRUE;
}
/*!
Returns the focus widget in this widget's window. This is not the
same as QApplication::focusWidget(), which returns the focus
widget in the currently active window.
*/
QWidget *QWidget::focusWidget() const
{
QWidget *that = (QWidget *)this; // mutable
QFocusData *f = that->focusData( FALSE );
if ( f && f->focusWidgets.count() && f->it.current() == 0 )
f->it.toFirst();
return ( f && f->it.current() ) ? f->it.current() : 0;
}
/*!
Returns the focus data for this widget's top-level widget.
Focus data always belongs to the top-level widget. The focus data
list contains all the widgets in this top-level widget that can
accept focus, in tab order. An iterator points to the current
focus widget (focusWidget() returns a pointer to this widget).
This information is useful for implementing advanced versions of
focusNextPrevChild().
*/
QFocusData * QWidget::focusData()
{
return focusData( TRUE );
}
/*!
\internal
Internal function which lets us ask for the focus data, creating
it if it doesn't exist and \a create is TRUE.
*/
QFocusData * QWidget::focusData( bool create )
{
QWidget * tlw = topLevelWidget();
QWExtra * ed = tlw->extraData();
if ( !ed || !ed->topextra ) {
if ( !create )
return 0;
tlw->createTLExtra();
ed = tlw->extraData();
}
if ( create && !ed->topextra->focusData )
ed->topextra->focusData = new QFocusData;
return ed->topextra->focusData;
}
/*!
\property QWidget::inputMethodEnabled
\brief enables or disables the use of input methods for this widget.
Most Widgets (as eg. buttons) that do not handle text input should have
the input method disabled if they have focus. This is the default.
If a widget handles text input it should set this property to TRUE.
*/
void QWidget::setInputMethodEnabled( bool b )
{
im_enabled = b;
#ifdef Q_WS_WIN
QInputContext::enable( this, im_enabled & !((bool)testWState(WState_Disabled)) );
#endif
}
/*!
Enables key event compression, if \a compress is TRUE, and
disables it if \a compress is FALSE.
Key compression is off by default (except for QLineEdit and
QTextEdit), so widgets receive one key press event for each key
press (or more, since autorepeat is usually on). If you turn it on
and your program doesn't keep up with key input, Qt may try to
compress key events so that more than one character can be
processed in each event.
For example, a word processor widget might receive 2, 3 or more
characters in each QKeyEvent::text(), if the layout recalculation
takes too long for the CPU.
If a widget supports multiple character unicode input, it is
always safe to turn the compression on.
Qt performs key event compression only for printable characters.
Modifier keys, cursor movement keys, function keys and
miscellaneous action keys (e.g. Escape, Enter, Backspace,
PrintScreen) will stop key event compression, even if there are
more compressible key events available.
Not all platforms support this compression, in which case turning
it on will have no effect.
\sa QKeyEvent::text();
*/
void QWidget::setKeyCompression(bool compress)
{
if ( compress )
setWState( WState_CompressKeys );
else
clearWState( WState_CompressKeys );
}
/*!
\property QWidget::isActiveWindow
\brief whether this widget is the active window
The active window is the window that contains the widget
that has keyboard focus.
When popup windows are visible, this property is TRUE for both the
active window \e and for the popup.
\sa setActiveWindow(), QApplication::activeWindow()
*/
bool QWidget::isActiveWindow() const
{
QWidget *tlw = topLevelWidget();
if(testWFlags(WSubWindow) && parentWidget())
tlw = parentWidget()->topLevelWidget();
if(tlw == qApp->activeWindow() || ( isVisible() && tlw->isPopup() ))
return TRUE;
#ifndef QT_NO_STYLE
const_cast<QWidget*>(this)->createExtra();
if (!extra->m_ceData) {
const_cast<QWidget*>(this)->extra->m_ceData = new QStyleControlElementData();
}
//extra->m_ceData->widgetObjectTypes = getObjectTypeListForObject(this);
extra->m_ceData->widgetObjectTypes.clear();
extra->m_ceData->allDataPopulated = false;
//if(style().styleHint(QStyle::SH_Widget_ShareActivation, *extra->m_ceData, getControlElementFlagsForObject(this, extra->m_ceData->widgetObjectTypes, QStyleOption(), false), QStyleOption(), NULL, this)) {
if(style().styleHint(QStyle::SH_Widget_ShareActivation, *extra->m_ceData, QStyle::CEF_None, QStyleOption(), NULL, this)) {
if((tlw->isDialog() || (tlw->testWFlags(Qt::WStyle_Tool) && !tlw->isPopup())) &&
!tlw->testWFlags(Qt::WShowModal) &&
(!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
return TRUE;
QWidget *w = qApp->activeWindow();
if( !testWFlags(WSubWindow) && w && w->testWFlags(WSubWindow) &&
w->parentWidget()->topLevelWidget() == tlw)
return TRUE;
while(w && (tlw->isDialog() || tlw->testWFlags(Qt::WStyle_Tool)) &&
!w->testWFlags(Qt::WShowModal) && w->parentWidget()) {
w = w->parentWidget()->topLevelWidget();
if( w == tlw )
return TRUE;
}
}
#endif
#if defined(Q_WS_WIN32)
HWND parent = tlw->winId();
HWND topparent = GetActiveWindow();
while ( parent ) {
parent = ::GetParent( parent );
if ( parent && parent == topparent )
return TRUE;
}
#endif
return FALSE;
}
/*!
Moves the \a second widget around the ring of focus widgets so
that keyboard focus moves from the \a first widget to the \a
second widget when the Tab key is pressed.
Note that since the tab order of the \a second widget is changed,
you should order a chain like this:
\code
setTabOrder( a, b ); // a to b
setTabOrder( b, c ); // a to b to c
setTabOrder( c, d ); // a to b to c to d
\endcode
\e not like this:
\code
setTabOrder( c, d ); // c to d WRONG
setTabOrder( a, b ); // a to b AND c to d
setTabOrder( b, c ); // a to b to c, but not c to d
\endcode
If \a first or \a second has a focus proxy, setTabOrder()
correctly substitutes the proxy.
\sa setFocusPolicy(), setFocusProxy()
*/
void QWidget::setTabOrder( QWidget* first, QWidget *second )
{
if ( !first || !second ||
first->focusPolicy() == NoFocus || second->focusPolicy() == NoFocus )
return;
// If first is redirected, set first to the last child of first
// that can take keyboard focus so that second is inserted after
// that last child, and the focus order within first is (more
// likely to be) preserved.
if ( first->focusProxy() ) {
QObjectList *l = first->queryList( "QWidget" );
if ( l && l->count() ) {
QObjectListIt it(*l);
it.toLast();
while (it.current()) {
if (((QWidget*)it.current())->topLevelWidget() == first->topLevelWidget()) {
first = (QWidget*)it.current();
if (first->focusPolicy() != NoFocus)
break;
}
--it;
}
}
delete l;
}
while ( first->focusProxy() )
first = first->focusProxy();
while ( second->focusProxy() )
second = second->focusProxy();
QFocusData *f = first->focusData( TRUE );
bool focusThere = (f->it.current() == second );
f->focusWidgets.removeRef( second );
if ( f->focusWidgets.findRef( first ) >= 0 )
f->focusWidgets.insert( f->focusWidgets.at() + 1, second );
else
f->focusWidgets.append( second );
if ( focusThere ) { // reset iterator so tab will work appropriately
f->it.toFirst();
while( f->it.current() && f->it.current() != second )
++f->it;
}
}
/*!\internal
Moves the relevant subwidgets of this widget from the \a oldtlw's
tab chain to that of the new parent, if there's anything to move and
we're really moving
This function is called from QWidget::reparent() *after* the widget
has been reparented.
\sa reparent()
*/
void QWidget::reparentFocusWidgets( QWidget * oldtlw )
{
if ( oldtlw == topLevelWidget() )
return; // nothing to do
QFocusData * from = oldtlw ? oldtlw->topData()->focusData : 0;
QFocusData * to;
to = focusData();
if ( from ) {
from->focusWidgets.first();
do {
QWidget * pw = from->focusWidgets.current();
while( pw && pw != this )
pw = pw->parentWidget();
if ( pw == this ) {
QWidget * w = from->focusWidgets.take();
if ( w == from->it.current() )
// probably best to clear keyboard focus, or
// the user might become rather confused
w->clearFocus();
if ( !isTopLevel() )
to->focusWidgets.append( w );
} else {
from->focusWidgets.next();
}
} while( from->focusWidgets.current() );
}
if ( to->focusWidgets.findRef(this) < 0 )
to->focusWidgets.append( this );
if ( !isTopLevel() && extra && extra->topextra && extra->topextra->focusData ) {
// this widget is no longer a top-level widget, so get rid
// of old focus data
delete extra->topextra->focusData;
extra->topextra->focusData = 0;
}
}
/*!
\fn void QWidget::recreate( QWidget *parent, WFlags f, const QPoint & p, bool showIt )
\obsolete
This method is provided to aid porting from Qt 1.0 to 2.0. It has
been renamed reparent() in Qt 2.0.
*/
/*!
\property QWidget::frameSize
\brief the size of the widget including any window frame
*/
QSize QWidget::frameSize() const
{
if ( isTopLevel() && !isPopup() ) {
if ( fstrut_dirty )
updateFrameStrut();
QWidget *that = (QWidget *) this;
QTLWExtra *top = that->topData();
return QSize( crect.width() + top->fleft + top->fright,
crect.height() + top->ftop + top->fbottom );
}
return crect.size();
}
/*!
\internal
Recursive function that updates \a widget and all its children,
if they have some parent background origin.
*/
static void qt_update_bg_recursive( QWidget *widget )
{
if ( !widget || widget->isHidden() || widget->backgroundOrigin() == QWidget::WidgetOrigin || !widget->backgroundPixmap() )
return;
const QObjectList *lst = widget->children();
if ( lst ) {
QObjectListIterator it( *lst );
QWidget *widget;
while ( (widget = (QWidget*)it.current()) ) {
++it;
if ( widget->isWidgetType() && !widget->isHidden() && !widget->isTopLevel() && !widget->testWFlags(Qt::WSubWindow) )
qt_update_bg_recursive( widget );
}
}
QApplication::postEvent( widget, new QPaintEvent( widget->clipRegion(), !widget->testWFlags(Qt::WRepaintNoErase) ) );
}
/*!
\overload
This corresponds to move( QPoint(\a x, \a y) ).
*/
void QWidget::move( int x, int y )
{
QPoint oldp(pos());
internalSetGeometry( x + geometry().x() - QWidget::x(),
y + geometry().y() - QWidget::y(),
width(), height(), TRUE );
if ( isVisible() && oldp != pos() )
qt_update_bg_recursive( this );
}
/*!
\overload
This corresponds to resize( QSize(\a w, \a h) ).
*/
void QWidget::resize( int w, int h )
{
internalSetGeometry( geometry().x(), geometry().y(), w, h, FALSE );
setWState( WState_Resized );
}
/*!
\overload
This corresponds to setGeometry( QRect(\a x, \a y, \a w, \a h) ).
*/
void QWidget::setGeometry( int x, int y, int w, int h )
{
QPoint oldp( pos( ));
internalSetGeometry( x, y, w, h, TRUE );
setWState( WState_Resized );
if ( isVisible() && oldp != pos() )
qt_update_bg_recursive( this );
}
/*!
\property QWidget::focusEnabled
\brief whether the widget accepts keyboard focus
Keyboard focus is initially disabled (i.e. focusPolicy() ==
\c QWidget::NoFocus).
You must enable keyboard focus for a widget if it processes
keyboard events. This is normally done from the widget's
constructor. For instance, the QLineEdit constructor calls
setFocusPolicy(QWidget::StrongFocus).
\sa setFocusPolicy(), focusInEvent(), focusOutEvent(), keyPressEvent(),
keyReleaseEvent(), isEnabled()
*/
/*!
\enum QWidget::FocusPolicy
This enum type defines the various policies a widget can have with
respect to acquiring keyboard focus.
\value TabFocus the widget accepts focus by tabbing.
\value ClickFocus the widget accepts focus by clicking.
\value StrongFocus the widget accepts focus by both tabbing
and clicking. On Mac OS X this will also
be indicate that the widget accepts tab focus
when in 'Text/List focus mode'.
\value WheelFocus like StrongFocus plus the widget accepts
focus by using the mouse wheel.
\value NoFocus the widget does not accept focus.
*/
/*!
\property QWidget::focusPolicy
\brief the way the widget accepts keyboard focus
The policy is \c QWidget::TabFocus if the widget accepts keyboard
focus by tabbing, \c QWidget::ClickFocus if the widget accepts
focus by clicking, \c QWidget::StrongFocus if it accepts both, and
\c QWidget::NoFocus (the default) if it does not accept focus at
all.
You must enable keyboard focus for a widget if it processes
keyboard events. This is normally done from the widget's
constructor. For instance, the QLineEdit constructor calls
setFocusPolicy(QWidget::StrongFocus).
\sa focusEnabled, focusInEvent(), focusOutEvent(), keyPressEvent(),
keyReleaseEvent(), enabled
*/
void QWidget::setFocusPolicy( FocusPolicy policy )
{
if ( focusProxy() )
focusProxy()->setFocusPolicy( policy );
if ( policy != NoFocus ) {
QFocusData * f = focusData( TRUE );
if ( f->focusWidgets.findRef( this ) < 0 )
f->focusWidgets.append( this );
}
focus_policy = (uint) policy;
}
/*!
\property QWidget::updatesEnabled
\brief whether updates are enabled
Calling update() and repaint() has no effect if updates are
disabled. Paint events from the window system are processed
normally even if updates are disabled.
setUpdatesEnabled() is normally used to disable updates for a
short period of time, for instance to avoid screen flicker during
large changes.
Example:
\code
setUpdatesEnabled( FALSE );
bigVisualChanges();
setUpdatesEnabled( TRUE );
repaint();
\endcode
\sa update(), repaint(), paintEvent()
*/
void QWidget::setUpdatesEnabled( bool enable )
{
if ( enable )
clearWState( WState_BlockUpdates );
else
setWState( WState_BlockUpdates );
}
/*!
Shows the widget and its child widgets.
If its size or position has changed, Qt guarantees that a widget
gets move and resize events just before it is shown.
You almost never have to reimplement this function. If you need to
change some settings before a widget is shown, use showEvent()
instead. If you need to do some delayed initialization use
polish().
\sa showEvent(), hide(), showMinimized(), showMaximized(),
showNormal(), isVisible(), polish()
*/
void QWidget::show()
{
if ( testWState(WState_Visible) )
return;
bool wasHidden = isHidden();
bool postLayoutHint = !isTopLevel() && wasHidden;
clearWState( WState_ForceHide | WState_CreatedHidden );
if ( !isTopLevel() && !parentWidget()->isVisible() ) {
// we should become visible, but one of our ancestors is
// explicitly hidden. Since we cleared the ForceHide flag, our
// immediate parent will call show() on us again during its
// own processing of show().
if ( wasHidden ) {
QEvent showToParentEvent( QEvent::ShowToParent );
QApplication::sendEvent( this, &showToParentEvent );
}
if ( postLayoutHint )
QApplication::postEvent( parentWidget(),
new QEvent(QEvent::LayoutHint) );
return;
}
in_show = TRUE; // set qws recursion watch
QApplication::sendPostedEvents( this, QEvent::ChildInserted );
uint state = isTopLevel() ? windowState() : 0;
#ifndef Q_OS_TEMP
if ( isTopLevel() && !testWState( WState_Resized ) ) {
// do this before sending the posted resize events. Otherwise
// the layout would catch the resize event and may expand the
// minimum size.
QSize s = qt_naturalWidgetSize( this );
if ( !s.isEmpty() )
resize( s );
}
#endif // Q_OS_TEMP
QApplication::sendPostedEvents( this, QEvent::Move );
QApplication::sendPostedEvents( this, QEvent::Resize );
// the resizing and layouting might have changed the window state
if (isTopLevel() && windowState() != state)
setWindowState(state);
setWState( WState_Visible );
if ( parentWidget() )
QApplication::sendPostedEvents( parentWidget(),
QEvent::ChildInserted );
if ( extra ) {
int w = crect.width();
int h = crect.height();
if ( w < extra->minw || h < extra->minh ||
w > extra->maxw || h > extra->maxh ) {
w = QMAX( extra->minw, QMIN( w, extra->maxw ));
h = QMAX( extra->minh, QMIN( h, extra->maxh ));
resize( w, h ); // deferred resize
}
}
if ( testWFlags(WStyle_Tool) || isPopup() ) {
raise();
} else if ( testWFlags(WType_TopLevel) ) {
while ( QApplication::activePopupWidget() ) {
if ( !QApplication::activePopupWidget()->close() )
break;
}
}
if ( !testWState(WState_Polished) )
polish();
showChildren( FALSE );
if ( postLayoutHint )
QApplication::postEvent( parentWidget(),
new QEvent(QEvent::LayoutHint) );
// Required for Mac, not sure whether we should always do that
if( isTopLevel() )
QApplication::sendPostedEvents(0, QEvent::LayoutHint);
// On Windows, show the popup now so that our own focus handling
// stores the correct old focus widget even if it's stolen in the showevent
#if defined(Q_WS_WIN)
if ( testWFlags(WType_Popup) )
qApp->openPopup( this );
#endif
QShowEvent showEvent;
QApplication::sendEvent( this, &showEvent );
if ( testWFlags(WShowModal) ) {
// qt_enter_modal *before* show, otherwise the initial
// stacking might be wrong
qt_enter_modal( this );
}
// do not show the window directly, but post a show-window request
// to reduce flicker with widgets in layouts
if ( postLayoutHint )
QApplication::postEvent( this, new QEvent( QEvent::ShowWindowRequest ) );
else
showWindow();
#if !defined(Q_WS_WIN)
if ( testWFlags(WType_Popup) )
qApp->openPopup( this );
#endif
#if defined(QT_ACCESSIBILITY_SUPPORT)
QAccessible::updateAccessibility( this, 0, QAccessible::ObjectShow );
#endif
in_show = FALSE; // reset qws recursion watch
}
/*! \fn void QWidget::iconify()
\obsolete
*/
/*!
Hides the widget.
You almost never have to reimplement this function. If you need to
do something after a widget is hidden, use hideEvent() instead.
\sa hideEvent(), isHidden(), show(), showMinimized(), isVisible(), close()
*/
void QWidget::hide()
{
clearWState( WState_CreatedHidden );
if ( testWState(WState_ForceHide) )
return;
setWState( WState_ForceHide );
if ( testWFlags(WType_Popup) )
qApp->closePopup( this );
// Move test modal here. Otherwise, a modal dialog could get
// destroyed and we lose all access to its parent because we haven't
// left modality. (Eg. modal Progress Dialog)
if ( testWFlags(WShowModal) )
qt_leave_modal( this );
#if defined(Q_WS_WIN)
if ( isTopLevel() && !isPopup() && parentWidget() && isActiveWindow() )
parentWidget()->setActiveWindow(); // Activate parent
#endif
hideWindow();
if ( testWState(WState_Visible) ) {
clearWState( WState_Visible );
// next bit tries to move the focus if the focus widget is now
// hidden.
if ( qApp && qApp->focusWidget() == this )
focusNextPrevChild( TRUE );
QHideEvent hideEvent;
QApplication::sendEvent( this, &hideEvent );
hideChildren( FALSE );
#if defined(QT_ACCESSIBILITY_SUPPORT)
QAccessible::updateAccessibility( this, 0, QAccessible::ObjectHide );
#endif
} else {
QEvent hideToParentEvent( QEvent::HideToParent );
QApplication::sendEvent( this, &hideToParentEvent );
}
// post layout hint for non toplevels. The parent widget check is
// necessary since the function is called in the destructor
if ( !isTopLevel() && parentWidget() )
QApplication::postEvent( parentWidget(),
new QEvent( QEvent::LayoutHint) );
}
void QWidget::setShown( bool show )
{
if ( show )
this->show();
else
hide();
}
void QWidget::setHidden( bool hide )
{
if ( hide )
this->hide();
else
show();
}
void QWidget::showChildren( bool spontaneous )
{
if ( children() ) {
QObjectListIt it(*children());
QObject *object;
QWidget *widget;
while ( it ) {
object = it.current();
++it;
if ( object->isWidgetType() ) {
widget = (QWidget*)object;
if ( !widget->isTopLevel() && widget->isShown() ) {
if ( spontaneous ) {
widget->showChildren( spontaneous );
QShowEvent e;
QApplication::sendSpontaneousEvent( widget, &e );
} else {
widget->show();
}
}
}
}
}
}
void QWidget::hideChildren( bool spontaneous )
{
if ( children() ) {
QObjectListIt it(*children());
QObject *object;
QWidget *widget;
while ( it ) {
object = it.current();
++it;
if ( object->isWidgetType() ) {
widget = (QWidget*)object;
if ( !widget->isTopLevel() && widget->isShown() ) {
if ( !spontaneous )
widget->clearWState( WState_Visible );
widget->hideChildren( spontaneous );
QHideEvent e;
if ( spontaneous )
QApplication::sendSpontaneousEvent( widget, &e );
else
QApplication::sendEvent( widget, &e );
}
}
}
}
}
/*!
Delayed initialization of a widget.
This function will be called \e after a widget has been fully
created and \e before it is shown the very first time.
Polishing is useful for final initialization which depends on
having an instantiated widget. This is something a constructor
cannot guarantee since the initialization of the subclasses might
not be finished.
After this function, the widget has a proper font and palette and
QApplication::polish() has been called.
Remember to call QWidget's implementation first when reimplementing this
function to ensure that your program does not end up in infinite recursion.
\sa constPolish(), QApplication::polish()
*/
void QWidget::polish()
{
#ifndef QT_NO_WIDGET_TOPEXTRA
if ( isTopLevel() ) {
const QPixmap *pm = icon();
if ( !pm || pm->isNull() ) {
QWidget *mw = (QWidget *)parent();
pm = mw ? mw->icon() : 0;
if ( pm && !pm->isNull() )
setIcon( *pm );
else {
mw = mw ? mw->topLevelWidget() : 0;
pm = mw ? mw->icon() : 0;
if ( pm && !pm->isNull() )
setIcon( *pm );
else {
mw = qApp ? qApp->mainWidget() : 0;
pm = mw ? mw->icon() : 0;
if ( pm && !pm->isNull() )
setIcon( *pm );
}
}
}
}
#endif
if ( !testWState(WState_Polished) ) {
if ( ! own_font &&
! QApplication::font( this ).isCopyOf( QApplication::font() ) )
unsetFont();
#ifndef QT_NO_PALETTE
if ( ! own_palette &&
! QApplication::palette( this ).isCopyOf( QApplication::palette() ) )
unsetPalette();
#endif
setWState(WState_Polished);
qApp->polish( this );
QApplication::sendPostedEvents( this, QEvent::ChildInserted );
}
}
/*!
\fn void QWidget::constPolish() const
Ensures that the widget is properly initialized by calling
polish().
Call constPolish() from functions like sizeHint() that depends on
the widget being initialized, and that may be called before
show().
\warning Do not call constPolish() on a widget from inside that
widget's constructor.
\sa polish()
*/
/*!
\overload
Closes this widget. Returns TRUE if the widget was closed;
otherwise returns FALSE.
If \a alsoDelete is TRUE or the widget has the \c
WDestructiveClose widget flag, the widget is also deleted. The
widget can prevent itself from being closed by rejecting the
\l QCloseEvent it gets. A close events is delivered to the widget
no matter if the widget is visible or not.
The QApplication::lastWindowClosed() signal is emitted when the
last visible top level widget is closed.
Note that closing the \l QApplication::mainWidget() terminates the
application.
\sa closeEvent(), QCloseEvent, hide(), QApplication::quit(),
QApplication::setMainWidget(), QApplication::lastWindowClosed()
*/
bool QWidget::close( bool alsoDelete )
{
if ( is_closing )
return TRUE;
is_closing = 1;
WId id = winId();
bool isMain = qApp->mainWidget() == this;
bool checkLastWindowClosed = isTopLevel() && !isPopup();
bool deleted = FALSE;
QCloseEvent e;
QApplication::sendEvent( this, &e );
deleted = !QWidget::find(id);
if ( !deleted && !e.isAccepted() ) {
is_closing = 0;
return FALSE;
}
if ( !deleted && !isHidden() )
hide();
if ( checkLastWindowClosed
&& qApp->receivers(SIGNAL(lastWindowClosed())) ) {
/* if there is no non-withdrawn top level window left (except
the desktop, popups, or dialogs with parents), we emit the
lastWindowClosed signal */
QWidgetList *list = qApp->topLevelWidgets();
QWidget *widget = list->first();
while ( widget ) {
if ( !widget->isHidden()
&& !widget->isDesktop()
&& !widget->isPopup()
&& (!widget->isDialog() || !widget->parentWidget()))
break;
widget = list->next();
}
delete list;
if ( widget == 0 )
emit qApp->lastWindowClosed();
}
if ( isMain )
qApp->quit();
if ( deleted )
return TRUE;
is_closing = 0;
if ( alsoDelete )
delete this;
else if ( testWFlags(WDestructiveClose) ) {
clearWFlags(WDestructiveClose);
deleteLater();
}
return TRUE;
}
/*!
\fn bool QWidget::close()
Closes this widget. Returns TRUE if the widget was closed;
otherwise returns FALSE.
First it sends the widget a QCloseEvent. The widget is \link
hide() hidden\endlink if it \link QCloseEvent::accept()
accepts\endlink the close event. The default implementation of
QWidget::closeEvent() accepts the close event.
The \l QApplication::lastWindowClosed() signal is emitted when the
last visible top level widget is closed.
*/
/*!
\property QWidget::visible
\brief whether the widget is visible
Calling show() sets the widget to visible status if all its parent
widgets up to the top-level widget are visible. If an ancestor is
not visible, the widget won't become visible until all its
ancestors are shown.
Calling hide() hides a widget explicitly. An explicitly hidden
widget will never become visible, even if all its ancestors become
visible, unless you show it.
A widget receives show and hide events when its visibility status
changes. Between a hide and a show event, there is no need to
waste CPU cycles preparing or displaying information to the user.
A video application, for example, might simply stop generating new
frames.
A widget that happens to be obscured by other windows on the
screen is considered to be visible. The same applies to iconified
top-level widgets and windows that exist on another virtual
desktop (on platforms that support this concept). A widget
receives spontaneous show and hide events when its mapping status
is changed by the window system, e.g. a spontaneous hide event
when the user minimizes the window, and a spontaneous show event
when the window is restored again.
\sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(),
showEvent(), hideEvent()
*/
/*!
Returns TRUE if this widget would become visible if \a ancestor is
shown; otherwise returns FALSE.
The TRUE case occurs if neither the widget itself nor any parent
up to but excluding \a ancestor has been explicitly hidden.
This function will still return TRUE if the widget is obscured by
other windows on the screen, but could be physically visible if it
or they were to be moved.
isVisibleTo(0) is identical to isVisible().
\sa show() hide() isVisible()
*/
bool QWidget::isVisibleTo(QWidget* ancestor) const
{
if ( !ancestor )
return isVisible();
const QWidget * w = this;
while ( w
&& w->isShown()
&& !w->isTopLevel()
&& w->parentWidget()
&& w->parentWidget() != ancestor )
w = w->parentWidget();
return w->isShown();
}
/*!
\fn bool QWidget::isVisibleToTLW() const
\obsolete
This function is deprecated. It is equivalent to isVisible()
*/
/*!
\property QWidget::hidden
\brief whether the widget is explicitly hidden
If FALSE, the widget is visible or would become visible if all its
ancestors became visible.
\sa hide(), show(), isVisible(), isVisibleTo(), shown
*/
/*!
\property QWidget::shown
\brief whether the widget is shown
If TRUE, the widget is visible or would become visible if all its
ancestors became visible.
\sa hide(), show(), isVisible(), isVisibleTo(), hidden
*/
/*!
\property QWidget::visibleRect
\brief the visible rectangle
\obsolete
No longer necessary, you can simply call repaint(). If you do not
need the rectangle for repaint(), use clipRegion() instead.
*/
QRect QWidget::visibleRect() const
{
QRect r = rect();
const QWidget * w = this;
int ox = 0;
int oy = 0;
while ( w
&& w->isVisible()
&& !w->isTopLevel()
&& w->parentWidget() ) {
ox -= w->x();
oy -= w->y();
w = w->parentWidget();
r = r.intersect( QRect( ox, oy, w->width(), w->height() ) );
}
if ( !w->isVisible() )
return QRect();
return r;
}
/*!
Returns the unobscured region where paint events can occur.
For visible widgets, this is an approximation of the area not
covered by other widgets; otherwise, this is an empty region.
The repaint() function calls this function if necessary, so in
general you do not need to call it.
*/
QRegion QWidget::clipRegion() const
{
return visibleRect();
}
/*!
Adjusts the size of the widget to fit the contents.
Uses sizeHint() if valid (i.e if the size hint's width and height
are \>= 0), otherwise sets the size to the children rectangle (the
union of all child widget geometries).
\sa sizeHint(), childrenRect()
*/
void QWidget::adjustSize()
{
QApplication::sendPostedEvents( 0, QEvent::ChildInserted );
QApplication::sendPostedEvents( 0, QEvent::LayoutHint );
if ( !testWState(WState_Polished) )
polish();
QSize s = sizeHint();
if ( isTopLevel() ) {
#if defined(Q_WS_X11)
QRect screen = QApplication::desktop()->screenGeometry( x11Screen() );
#else // all others
QRect screen = QApplication::desktop()->screenGeometry( pos() );
#endif
#ifndef QT_NO_LAYOUT
if ( layout() ) {
if ( layout()->hasHeightForWidth() ) {
s = s.boundedTo( screen.size() );
s.setHeight( layout()->totalHeightForWidth( s.width() ) );
}
} else
#endif
{
if ( sizePolicy().hasHeightForWidth() ) {
s = s.boundedTo( screen.size() );
s.setHeight( heightForWidth( s.width() ) );
}
}
}
if ( s.isValid() ) {
resize( s );
return;
}
QRect r = childrenRect(); // get children rectangle
if ( r.isNull() ) // probably no widgets
return;
resize( r.width() + 2 * r.x(), r.height() + 2 * r.y() );
}
/*!
\property QWidget::sizeHint
\brief the recommended size for the widget
If the value of this property is an invalid size, no size is
recommended.
The default implementation of sizeHint() returns an invalid size
if there is no layout for this widget, and returns the layout's
preferred size otherwise.
\sa QSize::isValid(), minimumSizeHint(), sizePolicy(),
setMinimumSize(), updateGeometry()
*/
QSize QWidget::sizeHint() const
{
#ifndef QT_NO_LAYOUT
if ( layout() )
return layout()->totalSizeHint();
#endif
return QSize( -1, -1 );
}
/*!
\property QWidget::minimumSizeHint
\brief the recommended minimum size for the widget
If the value of this property is an invalid size, no minimum size
is recommended.
The default implementation of minimumSizeHint() returns an invalid
size if there is no layout for this widget, and returns the
layout's minimum size otherwise. Most built-in widgets reimplement
minimumSizeHint().
\l QLayout will never resize a widget to a size smaller than
minimumSizeHint.
\sa QSize::isValid(), resize(), setMinimumSize(), sizePolicy()
*/
QSize QWidget::minimumSizeHint() const
{
#ifndef QT_NO_LAYOUT
if ( layout() )
return layout()->totalMinimumSize();
#endif
return QSize( -1, -1 );
}
/*!
\fn QWidget *QWidget::parentWidget( bool sameWindow ) const
Returns the parent of this widget, or 0 if it does not have any
parent widget. If \a sameWindow is TRUE and the widget is top
level returns 0; otherwise returns the widget's parent.
*/
/*!
\fn WFlags QWidget::testWFlags( WFlags f ) const
Returns the bitwise AND of the widget flags and \a f.
Widget flags are a combination of \l{Qt::WidgetFlags}.
If you want to test for the presence of multiple flags (or
composite flags such as \c WStyle_Splash), test the
return value for equality against the argument. For example:
\code
int flags = WStyle_Tool | WStyle_NoBorder;
if ( testWFlags(flags) )
... // WStyle_Tool or WStyle_NoBorder or both are set
if ( testWFlags(flags) == flags )
... // both WStyle_Tool and WStyle_NoBorder are set
\endcode
\sa getWFlags(), setWFlags(), clearWFlags()
*/
/*!
\fn WState QWidget::testWState( WState s ) const
\internal
Returns the bitwise AND of the widget states and \a s.
*/
/*!
\fn uint QWidget::getWState() const
\internal
Returns the current widget state.
*/
/*!
\fn void QWidget::clearWState( uint n )
\internal
Clears the widgets states \a n.
*/
/*!
\fn void QWidget::setWState( uint n )
\internal
Sets the widgets states \a n.
*/
/*****************************************************************************
QWidget event handling
*****************************************************************************/
/*!
This is the main event handler; it handles event \a e. You can
reimplement this function in a subclass, but we recommend using
one of the specialized event handlers instead.
The main event handler first passes an event through all \link
QObject::installEventFilter() event filters\endlink that have been
installed. If none of the filters intercept the event, it calls
one of the specialized event handlers.
Key press and release events are treated differently from other
events. event() checks for Tab and Shift+Tab and tries to move the
focus appropriately. If there is no widget to move the focus to
(or the key press is not Tab or Shift+Tab), event() calls
keyPressEvent().
This function returns TRUE if it is able to pass the event over to
someone (i.e. someone wanted the event); otherwise returns FALSE.
\sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(),
keyPressEvent(), keyReleaseEvent(), leaveEvent(),
mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(),
mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(),
QObject::event(), QObject::timerEvent()
*/
bool QWidget::event( QEvent *e )
{
if ( QObject::event( e ) )
return TRUE;
switch ( e->type() ) {
case QEvent::MouseMove:
mouseMoveEvent( (QMouseEvent*)e );
if ( ! ((QMouseEvent*)e)->isAccepted() )
return FALSE;
break;
case QEvent::MouseButtonPress:
// Don't reset input context here. Whether reset or not is
// a responsibility of input method. reset() will be
// called by mouseHandler() of input method if necessary
// via mousePressEvent() of text widgets.
#if 0
resetInputContext();
#endif
mousePressEvent( (QMouseEvent*)e );
if ( ! ((QMouseEvent*)e)->isAccepted() )
return FALSE;
break;
case QEvent::MouseButtonRelease:
mouseReleaseEvent( (QMouseEvent*)e );
if ( ! ((QMouseEvent*)e)->isAccepted() )
return FALSE;
break;
case QEvent::MouseButtonDblClick:
mouseDoubleClickEvent( (QMouseEvent*)e );
if ( ! ((QMouseEvent*)e)->isAccepted() )
return FALSE;
break;
#ifndef QT_NO_WHEELEVENT
case QEvent::Wheel:
wheelEvent( (QWheelEvent*)e );
if ( ! ((QWheelEvent*)e)->isAccepted() )
return FALSE;
break;
#endif
case QEvent::TabletMove:
case QEvent::TabletPress:
case QEvent::TabletRelease:
tabletEvent( (QTabletEvent*)e );
if ( ! ((QTabletEvent*)e)->isAccepted() )
return FALSE;
break;
case QEvent::Accel:
((QKeyEvent*)e)->ignore();
return FALSE;
case QEvent::KeyPress: {
QKeyEvent *k = (QKeyEvent *)e;
bool res = FALSE;
if ( !(k->state() & ControlButton || k->state() & AltButton) ) {
if ( k->key() == Key_Backtab ||
(k->key() == Key_Tab &&
(k->state() & ShiftButton)) ) {
QFocusEvent::setReason( QFocusEvent::Backtab );
res = focusNextPrevChild( FALSE );
QFocusEvent::resetReason();
} else if ( k->key() == Key_Tab ) {
QFocusEvent::setReason( QFocusEvent::Tab );
res = focusNextPrevChild( TRUE );
QFocusEvent::resetReason();
}
if ( res )
break;
}
keyPressEvent( k );
if ( !k->isAccepted() )
return FALSE;
}
break;
case QEvent::KeyRelease:
keyReleaseEvent( (QKeyEvent*)e );
if ( ! ((QKeyEvent*)e)->isAccepted() )
return FALSE;
break;
case QEvent::IMStart: {
QIMEvent *i = (QIMEvent *) e;
imStartEvent(i);
if (! i->isAccepted())
return FALSE;
}
break;
case QEvent::IMCompose: {
QIMEvent *i = (QIMEvent *) e;
imComposeEvent(i);
if (! i->isAccepted())
return FALSE;
}
break;
case QEvent::IMEnd: {
QIMEvent *i = (QIMEvent *) e;
imEndEvent(i);
if (! i->isAccepted())
return FALSE;
}
break;
case QEvent::FocusIn:
focusInEvent( (QFocusEvent*)e );
setFontSys();
break;
case QEvent::FocusOut:
focusOutEvent( (QFocusEvent*)e );
break;
case QEvent::Enter:
enterEvent( e );
break;
case QEvent::Leave:
leaveEvent( e );
break;
case QEvent::Paint:
// At this point the event has to be delivered, regardless
// whether the widget isVisible() or not because it
// already went through the filters
paintEvent( (QPaintEvent*)e );
break;
case QEvent::Move:
moveEvent( (QMoveEvent*)e );
break;
case QEvent::Resize:
resizeEvent( (QResizeEvent*)e );
break;
case QEvent::Close: {
QCloseEvent *c = (QCloseEvent *)e;
closeEvent( c );
if ( !c->isAccepted() )
return FALSE;
}
break;
case QEvent::ContextMenu: {
QContextMenuEvent *c = (QContextMenuEvent *)e;
contextMenuEvent( c );
if ( !c->isAccepted() )
return FALSE;
}
break;
#ifndef QT_NO_DRAGANDDROP
case QEvent::Drop:
dropEvent( (QDropEvent*) e);
break;
case QEvent::DragEnter:
dragEnterEvent( (QDragEnterEvent*) e);
break;
case QEvent::DragMove:
dragMoveEvent( (QDragMoveEvent*) e);
break;
case QEvent::DragLeave:
dragLeaveEvent( (QDragLeaveEvent*) e);
break;
#endif
case QEvent::Show:
showEvent( (QShowEvent*) e);
break;
case QEvent::Hide:
hideEvent( (QHideEvent*) e);
break;
case QEvent::ShowWindowRequest:
if ( isShown() )
showWindow();
break;
case QEvent::ParentFontChange:
if ( isTopLevel() )
break;
// fall through
case QEvent::ApplicationFontChange:
if ( own_font )
setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
else
unsetFont();
break;
#ifndef QT_NO_PALETTE
case QEvent::ParentPaletteChange:
if ( isTopLevel() )
break;
// fall through
case QEvent::ApplicationPaletteChange:
if ( !own_palette && !isDesktop() )
unsetPalette();
# if defined(Q_WS_QWS) && !defined (QT_NO_QWS_MANAGER)
if ( isTopLevel() && topData()->qwsManager ) {
QRegion r( topData()->qwsManager->region() );
QApplication::postEvent(topData()->qwsManager, new QPaintEvent(r, FALSE) );
}
# endif
break;
#endif
case QEvent::WindowActivate:
case QEvent::WindowDeactivate:
windowActivationChange( e->type() != QEvent::WindowActivate );
if ( children() ) {
QObjectListIt it( *children() );
QObject *o;
while( ( o = it.current() ) != 0 ) {
++it;
if ( o->isWidgetType() &&
((QWidget*)o)->isVisible() &&
!((QWidget*)o)->isTopLevel() )
QApplication::sendEvent( o, e );
}
}
break;
case QEvent::LanguageChange:
case QEvent::LocaleChange:
if ( children() ) {
QObjectListIt it( *children() );
QObject *o;
while( ( o = it.current() ) != 0 ) {
++it;
QApplication::sendEvent( o, e );
}
}
if ( e->type() == QEvent::LanguageChange ) {
int index = metaObject()->findSlot( "languageChange()", TRUE );
if ( index >= 0 )
qt_invoke( index, 0 );
}
update();
break;
#ifndef QT_NO_LAYOUT
case QEvent::LayoutDirectionChange:
if ( layout() ) {
layout()->activate();
} else {
QObjectList* llist = queryList( "QLayout", 0, TRUE, TRUE );
QObjectListIt lit( *llist );
QLayout *lay;
while ( ( lay = (QLayout*)lit.current() ) != 0 ) {
++lit;
lay->activate();
}
delete llist;
}
update();
break;
#endif
case QEvent::WindowStateChange:
{
QEvent::Type type;
if (isMinimized())
type = QEvent::ShowMinimized;
else if (isFullScreen())
type = QEvent::ShowFullScreen;
else if (isMaximized())
type = QEvent::ShowMaximized;
else
type = QEvent::ShowNormal;
QApplication::postEvent(this, new QEvent(type));
break;
}
case QEvent::WindowBlocked:
case QEvent::WindowUnblocked:
if ( children() ) {
QObjectListIt it( *children() );
QObject *o;
while( ( o = it.current() ) != 0 ) {
++it;
QWidget *w = ::qt_cast<QWidget*>(o);
if (w && !w->testWFlags(Qt::WShowModal))
QApplication::sendEvent( o, e );
}
}
break;
default:
return FALSE;
}
return TRUE;
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive mouse move events for the widget.
If mouse tracking is switched off, mouse move events only occur if
a mouse button is pressed while the mouse is being moved. If mouse
tracking is switched on, mouse move events occur even if no mouse
button is pressed.
QMouseEvent::pos() reports the position of the mouse cursor,
relative to this widget. For press and release events, the
position is usually the same as the position of the last mouse
move event, but it might be different if the user's hand shakes.
This is a feature of the underlying window system, not Qt.
\sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
mouseDoubleClickEvent(), event(), QMouseEvent
*/
void QWidget::mouseMoveEvent( QMouseEvent * e)
{
e->ignore();
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive mouse press events for the widget.
If you create new widgets in the mousePressEvent() the
mouseReleaseEvent() may not end up where you expect, depending on
the underlying window system (or X11 window manager), the widgets'
location and maybe more.
The default implementation implements the closing of popup widgets
when you click outside the window. For other widget types it does
nothing.
\sa mouseReleaseEvent(), mouseDoubleClickEvent(),
mouseMoveEvent(), event(), QMouseEvent
*/
void QWidget::mousePressEvent( QMouseEvent *e )
{
e->ignore();
if ( isPopup() ) {
e->accept();
QWidget* w;
while ( (w = qApp->activePopupWidget() ) && w != this ){
w->close();
if (qApp->activePopupWidget() == w) // widget does not want to dissappear
w->hide(); // hide at least
}
if (!rect().contains(e->pos()) ){
close();
}
}
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive mouse release events for the widget.
\sa mouseReleaseEvent(), mouseDoubleClickEvent(),
mouseMoveEvent(), event(), QMouseEvent
*/
void QWidget::mouseReleaseEvent( QMouseEvent * e )
{
e->ignore();
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive mouse double click events for the widget.
The default implementation generates a normal mouse press event.
Note that the widgets gets a mousePressEvent() and a
mouseReleaseEvent() before the mouseDoubleClickEvent().
\sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
event(), QMouseEvent
*/
void QWidget::mouseDoubleClickEvent( QMouseEvent *e )
{
mousePressEvent( e ); // try mouse press event
}
#ifndef QT_NO_WHEELEVENT
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive wheel events for the widget.
If you reimplement this handler, it is very important that you
\link QWheelEvent ignore()\endlink the event if you do not handle
it, so that the widget's parent can interpret it.
The default implementation ignores the event.
\sa QWheelEvent::ignore(), QWheelEvent::accept(), event(),
QWheelEvent
*/
void QWidget::wheelEvent( QWheelEvent *e )
{
e->ignore();
}
#endif
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive tablet events for the widget.
If you reimplement this handler, it is very important that you
\link QTabletEvent ignore()\endlink the event if you do not handle
it, so that the widget's parent can interpret it.
The default implementation ignores the event.
\sa QTabletEvent::ignore(), QTabletEvent::accept(), event(),
QTabletEvent
*/
void QWidget::tabletEvent( QTabletEvent *e )
{
e->ignore();
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive key press events for the widget.
A widget must call setFocusPolicy() to accept focus initially and
have focus in order to receive a key press event.
If you reimplement this handler, it is very important that you
explicitly \link QKeyEvent::ignore() ignore\endlink the event
if you do not understand it, so that the widget's parent can
interpret it; otherwise, the event will be implicitly accepted.
Although top-level widgets are able to choose whether to accept
or ignore unknown events because they have no parent widgets that
could otherwise handle them, it is good practice to explicitly
ignore events to make widgets as reusable as possible.
The default implementation closes popup widgets if the user
presses <b>Esc</b>. Otherwise the event is ignored.
\sa keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(),
focusInEvent(), focusOutEvent(), event(), QKeyEvent
*/
void QWidget::keyPressEvent( QKeyEvent *e )
{
if ( isPopup() && e->key() == Key_Escape ) {
e->accept();
close();
} else {
e->ignore();
}
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive key release events for the widget.
A widget must \link setFocusPolicy() accept focus\endlink
initially and \link hasFocus() have focus\endlink in order to
receive a key release event.
If you reimplement this handler, it is very important that you
\link QKeyEvent ignore()\endlink the release if you do not
understand it, so that the widget's parent can interpret it.
The default implementation ignores the event.
\sa keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(),
focusInEvent(), focusOutEvent(), event(), QKeyEvent
*/
void QWidget::keyReleaseEvent( QKeyEvent *e )
{
e->ignore();
}
/*!
This event handler can be reimplemented in a subclass to receive
keyboard focus events (focus received) for the widget.
A widget normally must setFocusPolicy() to something other than
\c NoFocus in order to receive focus events. (Note that the
application programmer can call setFocus() on any widget, even
those that do not normally accept focus.)
The default implementation updates the widget (except for toplevel
widgets that do not specify a focusPolicy() ). It also calls
setMicroFocusHint(), hinting any system-specific input tools about
the focus of the user's attention.
\sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
keyReleaseEvent(), event(), QFocusEvent
*/
void QWidget::focusInEvent( QFocusEvent * )
{
if ( focusPolicy() != NoFocus || !isTopLevel() ) {
update();
if ( testWState(WState_AutoMask) )
updateMask();
setMicroFocusHint(width()/2, 0, 1, height(), FALSE);
}
}
/*!
This event handler can be reimplemented in a subclass to receive
keyboard focus events (focus lost) for the widget.
A widget normally must setFocusPolicy() to something other than
\c NoFocus in order to receive focus events. (Note that the
application programmer can call setFocus() on any widget, even
those that do not normally accept focus.)
The default implementation updates the widget (except for toplevel
widgets that do not specify a focusPolicy() ). It also calls
setMicroFocusHint(), hinting any system-specific input tools about
the focus of the user's attention.
\sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
keyReleaseEvent(), event(), QFocusEvent
*/
void QWidget::focusOutEvent( QFocusEvent * )
{
if ( focusPolicy() != NoFocus || !isTopLevel() ){
update();
if ( testWState(WState_AutoMask) )
updateMask();
}
}
/*!
\property QWidget::microFocusHint
\brief the currently set micro focus hint for this widget.
See the documentation of setMicroFocusHint() for more information.
*/
QRect QWidget::microFocusHint() const
{
if ( !extra || extra->micro_focus_hint.isEmpty() )
return QRect(width()/2, 0, 1, height() );
else
return extra->micro_focus_hint;
}
/*!
This event handler can be reimplemented in a subclass to receive
widget enter events.
An event is sent to the widget when the mouse cursor enters the
widget.
\sa leaveEvent(), mouseMoveEvent(), event()
*/
void QWidget::enterEvent( QEvent * )
{
}
/*!
This event handler can be reimplemented in a subclass to receive
widget leave events.
A leave event is sent to the widget when the mouse cursor leaves
the widget.
\sa enterEvent(), mouseMoveEvent(), event()
*/
void QWidget::leaveEvent( QEvent * )
{
}
/*!
This event handler can be reimplemented in a subclass to receive
paint events.
A paint event is a request to repaint all or part of the widget.
It can happen as a result of repaint() or update(), or because the
widget was obscured and has now been uncovered, or for many other
reasons.
Many widgets can simply repaint their entire surface when asked
to, but some slow widgets need to optimize by painting only the
requested region: QPaintEvent::region(). This speed optimization
does not change the result, as painting is clipped to that region
during event processing. QListView and QCanvas do this, for
example.
Qt also tries to speed up painting by merging multiple paint
events into one. When update() is called several times or the
window system sends several paint events, Qt merges these events
into one event with a larger region (see QRegion::unite()).
repaint() does not permit this optimization, so we suggest using
update() when possible.
When the paint event occurs, the update region has normally been
erased, so that you're painting on the widget's background. There
are a couple of exceptions and QPaintEvent::erased() tells you
whether the widget has been erased or not.
The background can be set using setBackgroundMode(),
setPaletteBackgroundColor() or setBackgroundPixmap(). The
documentation for setBackgroundMode() elaborates on the
background; we recommend reading it.
\sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent
*/
void QWidget::paintEvent( QPaintEvent * )
{
}
/*!
This event handler can be reimplemented in a subclass to receive
widget move events. When the widget receives this event, it is
already at the new position.
The old position is accessible through QMoveEvent::oldPos().
\sa resizeEvent(), event(), move(), QMoveEvent
*/
void QWidget::moveEvent( QMoveEvent * )
{
}
/*!
This event handler can be reimplemented in a subclass to receive
widget resize events. When resizeEvent() is called, the widget
already has its new geometry. The old size is accessible through
QResizeEvent::oldSize().
The widget will be erased and receive a paint event immediately
after processing the resize event. No drawing need be (or should
be) done inside this handler.
Widgets that have been created with the \c WNoAutoErase flag
will not be erased. Nevertheless, they will receive a paint event
for their entire area afterwards. Again, no drawing needs to be
done inside this handler.
The default implementation calls updateMask() if the widget has
\link QWidget::setAutoMask() automatic masking\endlink enabled.
\sa moveEvent(), event(), resize(), QResizeEvent, paintEvent()
*/
void QWidget::resizeEvent( QResizeEvent * )
{
if ( testWState(WState_AutoMask) )
updateMask();
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive widget close events.
The default implementation calls e->accept(), which hides this
widget. See the \l QCloseEvent documentation for more details.
\sa event(), hide(), close(), QCloseEvent
*/
void QWidget::closeEvent( QCloseEvent *e )
{
e->accept();
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive widget context menu events.
The default implementation calls e->ignore(), which rejects the
context event. See the \l QContextMenuEvent documentation for
more details.
\sa event(), QContextMenuEvent
*/
void QWidget::contextMenuEvent( QContextMenuEvent *e )
{
e->ignore();
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive Input Method composition events. This handler
is called when the user begins entering text using an Input Method.
The default implementation calls e->ignore(), which rejects the
Input Method event. See the \l QIMEvent documentation for more
details.
\sa event(), QIMEvent
*/
void QWidget::imStartEvent( QIMEvent *e )
{
e->ignore();
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive Input Method composition events. This handler
is called when the user has entered some text using an Input Method.
The default implementation calls e->ignore(), which rejects the
Input Method event. See the \l QIMEvent documentation for more
details.
\sa event(), QIMEvent
*/
void QWidget::imComposeEvent( QIMEvent *e )
{
e->ignore();
}
/*!
This event handler, for event \a e, can be reimplemented in a
subclass to receive Input Method composition events. This handler
is called when the user has finished inputting text via an Input
Method.
The default implementation calls e->ignore(), which rejects the
Input Method event. See the \l QIMEvent documentation for more
details.
\sa event(), QIMEvent
*/
void QWidget::imEndEvent( QIMEvent *e )
{
e->ignore();
}
#ifndef QT_NO_DRAGANDDROP
/*!
This event handler is called when a drag is in progress and the
mouse enters this widget.
See the \link dnd.html Drag-and-drop documentation\endlink for an
overview of how to provide drag-and-drop in your application.
\sa QTextDrag, QImageDrag, QDragEnterEvent
*/
void QWidget::dragEnterEvent( QDragEnterEvent * )
{
}
/*!
This event handler is called when a drag is in progress and the
mouse enters this widget, and whenever it moves within the widget.
See the \link dnd.html Drag-and-drop documentation\endlink for an
overview of how to provide drag-and-drop in your application.
\sa QTextDrag, QImageDrag, QDragMoveEvent
*/
void QWidget::dragMoveEvent( QDragMoveEvent * )
{
}
/*!
This event handler is called when a drag is in progress and the
mouse leaves this widget.
See the \link dnd.html Drag-and-drop documentation\endlink for an
overview of how to provide drag-and-drop in your application.
\sa QTextDrag, QImageDrag, QDragLeaveEvent
*/
void QWidget::dragLeaveEvent( QDragLeaveEvent * )
{
}
/*!
This event handler is called when the drag is dropped on this
widget.
See the \link dnd.html Drag-and-drop documentation\endlink for an
overview of how to provide drag-and-drop in your application.
\sa QTextDrag, QImageDrag, QDropEvent
*/
void QWidget::dropEvent( QDropEvent * )
{
}
#endif // QT_NO_DRAGANDDROP
/*!
This event handler can be reimplemented in a subclass to receive
widget show events.
Non-spontaneous show events are sent to widgets immediately before
they are shown. The spontaneous show events of top-level widgets
are delivered afterwards.
\sa event(), QShowEvent
*/
void QWidget::showEvent( QShowEvent * )
{
}
/*!
This event handler can be reimplemented in a subclass to receive
widget hide events.
Hide events are sent to widgets immediately after they have been
hidden.
\sa event(), QHideEvent
*/
void QWidget::hideEvent( QHideEvent * )
{
}
/*
\fn QWidget::x11Event( MSG * )
This special event handler can be reimplemented in a subclass to
receive native X11 events.
In your reimplementation of this function, if you want to stop the
event being handled by Qt, return TRUE. If you return FALSE, this
native event is passed back to Qt, which translates the event into
a Qt event and sends it to the widget.
\warning This function is not portable.
\sa QApplication::x11EventFilter()
*/
#if defined(Q_WS_MAC)
/*!
This special event handler can be reimplemented in a subclass to
receive native Macintosh events.
In your reimplementation of this function, if you want to stop the
event being handled by Qt, return TRUE. If you return FALSE, this
native event is passed back to Qt, which translates the event into
a Qt event and sends it to the widget.
\warning This function is not portable.
\sa QApplication::macEventFilter()
*/
bool QWidget::macEvent( MSG * )
{
return FALSE;
}
#endif
#if defined(Q_WS_WIN)
/*!
This special event handler can be reimplemented in a subclass to
receive native Windows events.
In your reimplementation of this function, if you want to stop the
event being handled by Qt, return TRUE. If you return FALSE, this
native event is passed back to Qt, which translates the event into
a Qt event and sends it to the widget.
\warning This function is not portable.
\sa QApplication::winEventFilter()
*/
bool QWidget::winEvent( MSG * )
{
return FALSE;
}
#endif
#if defined(Q_WS_X11)
/*!
This special event handler can be reimplemented in a subclass to
receive native X11 events.
In your reimplementation of this function, if you want to stop the
event being handled by Qt, return TRUE. If you return FALSE, this
native event is passed back to Qt, which translates the event into
a Qt event and sends it to the widget.
\warning This function is not portable.
\sa QApplication::x11EventFilter()
*/
bool QWidget::x11Event( XEvent * )
{
return FALSE;
}
#endif
#if defined(Q_WS_QWS)
/*!
This special event handler can be reimplemented in a subclass to
receive native Qt/Embedded events.
In your reimplementation of this function, if you want to stop the
event being handled by Qt, return TRUE. If you return FALSE, this
native event is passed back to Qt, which translates the event into
a Qt event and sends it to the widget.
\warning This function is not portable.
\sa QApplication::qwsEventFilter()
*/
bool QWidget::qwsEvent( QWSEvent * )
{
return FALSE;
}
#endif
/*!
\property QWidget::autoMask
\brief whether the auto mask feature is enabled for the widget
Transparent widgets use a mask to define their visible region.
QWidget has some built-in support to make the task of
recalculating the mask easier. When setting auto mask to TRUE,
updateMask() will be called whenever the widget is resized or
changes its focus state. Note that you must reimplement
updateMask() (which should include a call to setMask()) or nothing
will happen.
Note: when you re-implement resizeEvent(), focusInEvent() or
focusOutEvent() in your custom widgets and still want to ensure
that the auto mask calculation works, you should add:
\code
if ( autoMask() )
updateMask();
\endcode
at the end of your event handlers. This is true for all member
functions that change the appearance of the widget in a way that
requires a recalculation of the mask.
While being a technically appealing concept, masks have a big
drawback: when using complex masks that cannot be expressed easily
with relatively simple regions, they can be very slow on some
window systems. The classic example is a transparent label. The
complex shape of its contents makes it necessary to represent its
mask by a bitmap, which consumes both memory and time. If all you
want is to blend the background of several neighboring widgets
together seamlessly, you will probably want to use
setBackgroundOrigin() rather than a mask.
\sa autoMask() updateMask() setMask() clearMask() setBackgroundOrigin()
*/
bool QWidget::autoMask() const
{
return testWState(WState_AutoMask);
}
void QWidget::setAutoMask( bool enable )
{
if ( enable == autoMask() )
return;
if ( enable ) {
setWState(WState_AutoMask);
updateMask();
} else {
clearWState(WState_AutoMask);
clearMask();
}
}
/*!
\enum QWidget::BackgroundOrigin
This enum defines the origin used to draw a widget's background
pixmap.
The pixmap is drawn using the:
\value WidgetOrigin widget's coordinate system.
\value ParentOrigin parent's coordinate system.
\value WindowOrigin top-level window's coordinate system.
\value AncestorOrigin same origin as the parent uses.
*/
/*!
\property QWidget::backgroundOrigin
\brief the origin of the widget's background
The origin is either WidgetOrigin (the default), ParentOrigin,
WindowOrigin or AncestorOrigin.
This only makes a difference if the widget has a background
pixmap, in which case positioning matters. Using \c WindowOrigin
for several neighboring widgets makes the background blend
together seamlessly. \c AncestorOrigin allows blending backgrounds
seamlessly when an ancestor of the widget has an origin other than
\c WindowOrigin.
\sa backgroundPixmap(), setBackgroundMode()
*/
QWidget::BackgroundOrigin QWidget::backgroundOrigin() const
{
return extra ? (BackgroundOrigin)extra->bg_origin : WidgetOrigin;
}
void QWidget::setBackgroundOrigin( BackgroundOrigin origin )
{
if ( origin == backgroundOrigin() )
return;
createExtra();
extra->bg_origin = origin;
update();
}
/*!
This function can be reimplemented in a subclass to support
transparent widgets. It should be called whenever a widget changes
state in a way that means that the shape mask must be recalculated.
\sa setAutoMask(), updateMask(), setMask(), clearMask()
*/
void QWidget::updateMask()
{
}
/*!
\internal
Returns the offset of the widget from the backgroundOrigin.
\sa setBackgroundMode(), backgroundMode(),
*/
QPoint QWidget::backgroundOffset() const
{
if (!isTopLevel()) {
switch(backgroundOrigin()) {
case WidgetOrigin:
break;
case ParentOrigin:
return pos();
case WindowOrigin:
{
const QWidget *topl = this;
while(topl && !topl->isTopLevel() && !topl->testWFlags(Qt::WSubWindow))
topl = topl->parentWidget(TRUE);
return mapTo((QWidget *)topl, QPoint(0, 0) );
}
case AncestorOrigin:
{
const QWidget *topl = this;
bool ancestorIsWindowOrigin = FALSE;
while(topl && !topl->isTopLevel() && !topl->testWFlags(Qt::WSubWindow))
{
if (!ancestorIsWindowOrigin) {
if (topl->backgroundOrigin() == QWidget::WidgetOrigin)
break;
if (topl->backgroundOrigin() == QWidget::ParentOrigin)
{
topl = topl->parentWidget(TRUE);
break;
}
if (topl->backgroundOrigin() == QWidget::WindowOrigin)
ancestorIsWindowOrigin = TRUE;
}
topl = topl->parentWidget(TRUE);
}
return mapTo((QWidget *) topl, QPoint(0,0) );
}
}
}
// fall back
return QPoint(0,0);
}
/*!
\fn QLayout* QWidget::layout () const
Returns the layout engine that manages the geometry of this
widget's children.
If the widget does not have a layout, layout() returns 0.
\sa sizePolicy()
*/
/* Sets this widget to use layout \a l to manage the geometry of its
children.
If the widget already had a layout, the old layout is
forgotten. (Note that it is not deleted.)
\sa layout() QLayout sizePolicy()
*/
#ifndef QT_NO_LAYOUT
void QWidget::setLayout( QLayout *l )
{
lay_out = l;
}
#endif
/*!
\property QWidget::sizePolicy
\brief the default layout behavior of the widget
If there is a QLayout that manages this widget's children, the
size policy specified by that layout is used. If there is no such
QLayout, the result of this function is used.
The default policy is Preferred/Preferred, which means that the
widget can be freely resized, but prefers to be the size
sizeHint() returns. Button-like widgets set the size policy to
specify that they may stretch horizontally, but are fixed
vertically. The same applies to lineedit controls (such as
QLineEdit, QSpinBox or an editable QComboBox) and other
horizontally orientated widgets (such as QProgressBar).
QToolButton's are normally square, so they allow growth in both
directions. Widgets that support different directions (such as
QSlider, QScrollBar or QHeader) specify stretching in the
respective direction only. Widgets that can provide scrollbars
(usually subclasses of QScrollView) tend to specify that they can
use additional space, and that they can make do with less than
sizeHint().
\sa sizeHint() QLayout QSizePolicy updateGeometry()
*/
QSizePolicy QWidget::sizePolicy() const
{
return extra ? extra->size_policy
: QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
}
void QWidget::setSizePolicy( QSizePolicy policy )
{
setWState( WState_OwnSizePolicy );
if ( policy == sizePolicy() )
return;
createExtra();
extra->size_policy = policy;
updateGeometry();
}
/*!
\overload void QWidget::setSizePolicy( QSizePolicy::SizeType hor, QSizePolicy::SizeType ver, bool hfw )
Sets the size policy of the widget to \a hor, \a ver and \a hfw
(height for width).
\sa QSizePolicy::QSizePolicy()
*/
/*!
Returns the preferred height for this widget, given the width \a
w. The default implementation returns 0, indicating that the
preferred height does not depend on the width.
\warning Does not look at the widget's layout.
*/
int QWidget::heightForWidth( int w ) const
{
(void)w;
return 0;
}
/*!
\property QWidget::customWhatsThis
\brief whether the widget wants to handle What's This help manually
The default implementation of customWhatsThis() returns FALSE,
which means the widget will not receive any events in Whats This
mode.
The widget may leave What's This mode by calling
QWhatsThis::leaveWhatsThisMode(), with or without actually
displaying any help text.
You can also reimplement customWhatsThis() if your widget is a
"passive interactor" supposed to work under all circumstances.
Simply don't call QWhatsThis::leaveWhatsThisMode() in that case.
\sa QWhatsThis::inWhatsThisMode() QWhatsThis::leaveWhatsThisMode()
*/
bool QWidget::customWhatsThis() const
{
return FALSE;
}
/*!
Returns the visible child widget at pixel position \a (x, y) in
the widget's own coordinate system.
If \a includeThis is TRUE, and there is no child visible at \a (x,
y), the widget itself is returned.
*/
QWidget *QWidget::childAt( int x, int y, bool includeThis ) const
{
if ( !rect().contains( x, y ) )
return 0;
if ( children() ) {
QObjectListIt it( *children() );
it.toLast();
QWidget *w, *t;
while( (w=(QWidget *)it.current()) != 0 ) {
--it;
if ( w->isWidgetType() && !w->isTopLevel() && !w->isHidden() ) {
if ( ( t = w->childAt( x - w->x(), y - w->y(), TRUE ) ) )
return t;
}
}
}
if ( includeThis )
return (QWidget*)this;
return 0;
}
/*!
\overload
Returns the visible child widget at point \a p in the widget's own
coordinate system.
If \a includeThis is TRUE, and there is no child visible at \a p,
the widget itself is returned.
*/
QWidget *QWidget::childAt( const QPoint & p, bool includeThis ) const
{
return childAt( p.x(), p.y(), includeThis );
}
/*!
Notifies the layout system that this widget has changed and may
need to change geometry.
Call this function if the sizeHint() or sizePolicy() have changed.
For explicitly hidden widgets, updateGeometry() is a no-op. The
layout system will be notified as soon as the widget is shown.
*/
void QWidget::updateGeometry()
{
QWidget *parent = parentWidget();
if (parent && !isTopLevel() && isShown())
QApplication::postEvent(parent, new QEvent(QEvent::LayoutHint));
}
/*!
Reparents the widget. The widget gets a new \a parent, new widget
flags (\a f, but as usual, use 0) at a new position in its new
parent (\a p).
If \a showIt is TRUE, show() is called once the widget has been
reparented.
If the new parent widget is in a different top-level widget, the
reparented widget and its children are appended to the end of the
\link setFocusPolicy() tab chain \endlink of the new parent
widget, in the same internal order as before. If one of the moved
widgets had keyboard focus, reparent() calls clearFocus() for that
widget.
If the new parent widget is in the same top-level widget as the
old parent, reparent doesn't change the tab order or keyboard
focus.
\warning It is extremely unlikely that you will ever need this
function. If you have a widget that changes its content
dynamically, it is far easier to use \l QWidgetStack or \l
QWizard.
\sa getWFlags()
*/
void QWidget::reparent( QWidget *parent, WFlags f, const QPoint &p,
bool showIt )
{
reparentSys( parent, f, p, showIt );
QEvent e( QEvent::Reparent );
QApplication::sendEvent( this, &e );
if (!own_font)
unsetFont();
else
setFont( fnt.resolve( qt_naturalWidgetFont( this ) ) );
#ifndef QT_NO_PALETTE
if (!own_palette)
unsetPalette();
#endif
}
/*!
\overload
A convenience version of reparent that does not take widget flags
as argument.
Calls reparent(\a parent, getWFlags() \& ~\l WType_Mask, \a p, \a
showIt).
*/
void QWidget::reparent( QWidget *parent, const QPoint & p,
bool showIt )
{
reparent( parent, getWFlags() & ~WType_Mask, p, showIt );
}
/*!
\property QWidget::ownCursor
\brief whether the widget uses its own cursor
If FALSE, the widget uses its parent widget's cursor.
\sa cursor
*/
/*!
\property QWidget::ownFont
\brief whether the widget uses its own font
If FALSE, the widget uses its parent widget's font.
\sa font
*/
/*!
\property QWidget::ownPalette
\brief whether the widget uses its own palette
If FALSE, the widget uses its parent widget's palette.
\sa palette
*/
void QWidget::repaint( bool erase )
{
repaint( visibleRect(), erase );
}
/*!\obsolete Use paletteBackgroundColor() or eraseColor() instead. */
const QColor & QWidget::backgroundColor() const { return eraseColor(); }
/*!\obsolete Use setPaletteBackgroundColor() or setEraseColor() instead. */
void QWidget::setBackgroundColor( const QColor &c ) { setEraseColor( c ); }
/*!\obsolete Use paletteBackgroundPixmap() or erasePixmap() instead. */
const QPixmap *QWidget::backgroundPixmap() const { return erasePixmap(); }
/*!\obsolete Use setPaletteBackgroundPixmap() or setErasePixmap() instead. */
void QWidget::setBackgroundPixmap( const QPixmap &pm ) { setErasePixmap( pm ); }
// documentation in qdesktopwidget_win.cpp
void QDesktopWidget::insertChild( QObject *obj )
{
if ( obj->isWidgetType() )
return;
QWidget::insertChild( obj );
}
/*!
\property QWidget::windowOpacity
\brief The level of opacity for the window.
The valid range of opacity is from 1.0 (completely opaque) to
0.0 (completely transparent).
By default the value of this property is 1.0.
This feature is only present on Mac OS X and Windows 2000 and up.
\warning Changing this property from opaque to transparent might issue a
paint event that needs to be processed before the window is displayed
correctly. This affects mainly the use of QPixmap::grabWindow(). Also note
that semi-transparent windows update and resize significantely slower than
opaque windows.
*/
|