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
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qquickpopup_p.h"
#include "qquickpopup_p_p.h"
#include "qquickpopupanchors_p.h"
#include "qquickpopupitem_p_p.h"
#include "qquickpopupwindow_p_p.h"
#include "qquickpopuppositioner_p_p.h"
#include "qquickapplicationwindow_p.h"
#include "qquickoverlay_p_p.h"
#include "qquickcontrol_p_p.h"
#if QT_CONFIG(quicktemplates2_container)
#include "qquickdialog_p.h"
#endif
#include <QtCore/qloggingcategory.h>
#include <QtQml/qqmlinfo.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/private/qquickaccessibleattached_p.h>
#include <QtQuick/private/qquicktransition_p.h>
#include <QtQuick/private/qquickitem_p.h>
#include <qpa/qplatformintegration.h>
#include <private/qguiapplication_p.h>
QT_BEGIN_NAMESPACE
Q_STATIC_LOGGING_CATEGORY(lcDimmer, "qt.quick.controls.popup.dimmer")
Q_STATIC_LOGGING_CATEGORY(lcQuickPopup, "qt.quick.controls.popup")
/*!
\qmltype Popup
\inherits QtObject
//! \nativetype QQuickPopup
\inqmlmodule QtQuick.Controls
\since 5.7
\ingroup qtquickcontrols-popups
\ingroup qtquickcontrols-focusscopes
\brief Base type of popup-like user interface controls.
Popup is the base type of popup-like user interface controls. It can be
used with \l Window or \l ApplicationWindow.
\qml
import QtQuick.Window
import QtQuick.Controls
ApplicationWindow {
id: window
width: 400
height: 400
visible: true
Button {
text: "Open"
onClicked: popup.open()
}
Popup {
id: popup
x: 100
y: 100
width: 200
height: 300
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
}
}
\endqml
Popup does not provide a layout of its own, but requires you to position
its contents, for instance by creating a \l RowLayout or a \l ColumnLayout.
Items declared as children of a Popup are automatically parented to the
Popups's \l contentItem. Items created dynamically need to be explicitly
parented to the contentItem.
\section1 Popup Layout
The following diagram illustrates the layout of a popup within a window:
\image qtquickcontrols-popup.png
The \l implicitWidth and \l implicitHeight of a popup are typically based
on the implicit sizes of the background and the content item plus any insets
and paddings. These properties determine how large the popup will be when no
explicit \l width or \l height is specified.
The geometry of the \l contentItem is determined by the padding. The following
example reserves 10px padding between the boundaries of the popup and its content:
\code
Popup {
padding: 10
contentItem: Text {
text: "Content"
}
}
\endcode
The \l background item fills the entire width and height of the popup,
unless insets or an explicit size have been given for it.
Negative insets can be used to make the background larger than the popup.
The following example uses negative insets to place a shadow outside the
popup's boundaries:
\code
Popup {
topInset: -2
leftInset: -2
rightInset: -6
bottomInset: -6
background: BorderImage {
source: ":/images/shadowed-background.png"
}
}
\endcode
\section1 Popup type
Since Qt 6.8, some popups, such as \l Menu, offer three different implementations,
depending on the platform. You can choose which one you prefer by setting \l popupType.
Whether a popup will be able to use the preferred type depends on the platform.
\c Popup.Item is supported on all platforms, but \c Popup.Window and \c Popup.Native
are normally only supported on desktop platforms. Additionally, if a popup is a
\l Menu inside a \l {Native menu bars}{native menubar}, the menu will be native as
well. And if the menu is a sub-menu inside another menu, the parent (or root) menu
will decide the type.
\section2 Showing a popup as an item
By setting \l popupType to \c Popup.Item, the popup will \e not be shown as a separate
window, but as an item inside the same scene as the parent. This item is parented
to that scene's \l{Overlay::overlay}{overlay}, and styled to look like an actual window.
This option is especially useful on platforms that doesn't support multiple windows.
This was also the only option before Qt 6.8.
In order to ensure that a popup is displayed above other items in the
scene, it is recommended to use ApplicationWindow. ApplicationWindow also
provides background dimming effects.
\section2 Showing a popup as a separate window
By setting \l popupType to \c Popup.Window, the popup will be shown inside a top-level
\l {QQuickWindow}{window} configured with the \l Qt::Popup flag. Using a window to show a
popup has the advantage that the popup will float on top of the parent window, and
can be placed outside of its geometry. The popup will otherwise look the same as when
using \c Popup.Item, that is, it will use the same QML delegates and styling as
when using \c Popup.Item.
\note If the platform doesn't support \c Popup.Window, \c Popup.Item will be used as fallback.
\section2 Showing a native popup
By setting \l popupType to \c Popup.Native, the popup will be shown using a platform
native popup window. This window, and all its contents, will be rendered by the
platform, and not by QML. This means that the QML delegates assigned to the popup
will \e not be used for rendering. If you for example
use this option on a \l Menu, it will be implemented using platform-specific
menu APIs. This will normally make the popup look and feel more native than for example
\c Popup.Window, but at the same time, suffer from platform limitations and differences
related to appearance and behavior. Such limitations are documented in more detail
in the subclasses that are affected, such as for a
\l {Limitations when using native menus}{Menu}).
\note If the platform doesn't support \c Popup.Native, \c Popup.Window will be used as fallback.
\section1 Popup Sizing
If only a single item is used within a Popup, it will resize to fit the
implicit size of its contained item. This makes it particularly suitable
for use together with layouts.
\code
Popup {
ColumnLayout {
anchors.fill: parent
CheckBox { text: qsTr("E-mail") }
CheckBox { text: qsTr("Calendar") }
CheckBox { text: qsTr("Contacts") }
}
}
\endcode
Sometimes there might be two items within the popup:
\code
Popup {
SwipeView {
// ...
}
PageIndicator {
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
}
}
\endcode
In this case, Popup cannot calculate a sensible implicit size. Since we're
anchoring the \l PageIndicator over the \l SwipeView, we can simply set the
content size to the view's implicit size:
\code
Popup {
contentWidth: view.implicitWidth
contentHeight: view.implicitHeight
SwipeView {
id: view
// ...
}
PageIndicator {
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
}
}
\endcode
\note When using \l {Showing a popup as an item}{popup items}, the popup's
\l{contentItem}{content item} gets parented to the \l{Overlay::}{overlay},
and does not live within the popup's parent. Because of that, a \l{Item::}
{scale} applied to the tree in which the popup lives does not apply to the
visual popup. To make the popup of e.g. a \l{ComboBox} follow the scale of
the combobox, apply the same scale to the \l{Overlay::}{overlay} as well:
\code
Window {
property double scaleFactor: 2.0
Scale {
id: scale
xScale: scaleFactor
yScale: scaleFactor
}
Item {
id: scaledContent
transform: scale
ComboBox {
id: combobox
// ...
}
}
Overlay.overlay.transform: scale
}
\endcode
\section1 Popup Positioning
Similar to items in Qt Quick, Popup's \l x and \l y coordinates are
relative to its parent. This means that opening a popup that is a
child of a \l Button, for example, will cause the popup to be positioned
relative to the button.
\include qquickoverlay-popup-parent.qdocinc
Another way to center a popup in the window regardless of its parent item
is to use \l {anchors.centerIn}:
\snippet qtquickcontrols-popup.qml centerIn
To ensure that the popup is positioned within the bounds of the enclosing
window, the \l margins property can be set to a non-negative value.
\section1 Showing Non-Child Items in Front of Popup
In cases where \l {Showing a popup as an item}{popup windows} are not being used,
Popup sets its contentItem's \l{qtquick-visualcanvas-visualparent.html}{visual parent}
to be the window's \l{Overlay::overlay}{overlay}, in order to ensure that
the popup appears in front of everything else in the scene.
In some cases, it might be useful to put an item in front of a popup,
such as a \l [QML QtVirtualKeyboard] {InputPanel} {virtual keyboard}.
This can be done by setting the item's parent to the overlay,
and giving the item a positive z value. The same result can also be
achieved by waiting until the popup is opened, before re-parenting the item
to the overlay.
\omit
This shouldn't be a snippet, since we don't want VKB to be a dependency to controls.
\endomit
\qml
Popup {
id: popup
visible: true
anchors.centerIn: parent
margins: 10
closePolicy: Popup.CloseOnEscape
ColumnLayout {
TextField {
placeholderText: qsTr("Username")
}
TextField {
placeholderText: qsTr("Password")
echoMode: TextInput.Password
}
}
}
InputPanel {
parent: Overlay.overlay
width: parent.width
y: popup.y + popup.topMargin + (window.activeFocusItem?.y ?? 0) + (window.activeFocusItem?.height ?? 0)
z: 1
}
\endqml
\section1 Popup Transitions
Since Qt 5.15.3 the following properties are restored to their original values from before
the enter transition after the exit transition is completed.
\list
\li \l opacity
\li \l scale
\endlist
This allows the built-in styles to animate on these properties without losing any explicitly
defined value.
\section1 Back/Escape Event Handling
By default, a Popup will close if:
\list
\li It has \l activeFocus,
\li Its \l closePolicy is \c {Popup.CloseOnEscape}, and
\li The user presses the key sequence for QKeySequence::Cancel (typically
the Escape key)
\endlist
To prevent this from happening, either:
\list
\li Don't give the popup \l focus.
\li Set the popup's \l closePolicy to a value that does not include
\c {Popup.CloseOnEscape}.
\li Handle \l {Keys}' \l {Keys::}{escapePressed} signal in a child item of
the popup so that it gets the event before the Popup.
\endlist
\sa {Popup Controls}, {Customizing Popup}, ApplicationWindow
\section1 Property Propagation
Popup inherits fonts, palettes and attached properties through its parent
window, not its \l {Visual Parent}{object or visual parent}:
\snippet qtquickcontrols-popup-property-propagation.qml file
\image qtquickcontrols-basic-popup-property-propagation.png
In addition, popups do not propagate their properties to child popups. This
behavior is modelled on Qt Widgets, where a \c Qt::Popup widget is a
top-level window. Top-level windows do not propagate their properties to
child windows.
Certain derived types like ComboBox are typically implemented in such a way
that the popup is considered an integral part of the control, and as such,
may inherit things like attached properties. For example, in the
\l {Material Style}{Material style} ComboBox, the theme and other attached
properties are explicitly inherited by the Popup from the ComboBox itself:
\code
popup: T.Popup {
// ...
Material.theme: control.Material.theme
Material.accent: control.Material.accent
Material.primary: control.Material.primary
}
\endcode
So, to ensure that a child popup has the same property values as its parent
popup, explicitly set those properties:
\code
Popup {
id: parentPopup
// ...
Popup {
palette: parentPopup.palette
}
}
\endcode
\section1 Polish Behavior of Closed Popups
When a popup is closed, it has no associated window, and neither do its
child items. This means that any child items will not be
\l {QQuickItem::polish}{polished} until the popup is shown. For this
reason, you cannot, for example, rely on a \l ListView within a closed
\c Popup to update its \c count property:
\code
import QtQuick
import QtQuick.Controls
ApplicationWindow {
width: 640
height: 480
visible: true
SomeModel {
id: someModel
}
Button {
text: view.count
onClicked: popup.open()
}
Popup {
id: popup
width: 400
height: 400
contentItem: ListView {
id: view
model: someModel
delegate: Label {
text: display
required property string display
}
}
}
}
\endcode
In the example above, the Button's text will not update when rows are added
to or removed from \c someModel after \l {Component::completed}{component
completion} while the popup is closed.
Instead, a \c count property can be added to \c SomeModel that is updated
whenever the \l {QAbstractItemModel::}{rowsInserted}, \l
{QAbstractItemModel::}{rowsRemoved}, and \l
{QAbstractItemModel::}{modelReset} signals are emitted. The \c Button can
then bind this property to its \c text.
*/
/*!
\qmlsignal void QtQuick.Controls::Popup::opened()
This signal is emitted when the popup is opened.
\sa aboutToShow()
*/
/*!
\qmlsignal void QtQuick.Controls::Popup::closed()
This signal is emitted when the popup is closed.
\sa aboutToHide()
*/
/*!
\qmlsignal void QtQuick.Controls::Popup::aboutToShow()
This signal is emitted when the popup is about to show.
\sa opened()
*/
/*!
\qmlsignal void QtQuick.Controls::Popup::aboutToHide()
This signal is emitted when the popup is about to hide.
\sa closed()
*/
QQuickItem *QQuickPopup::findParentItem() const
{
QObject *obj = parent();
while (obj) {
QQuickItem *item = qobject_cast<QQuickItem *>(obj);
if (item)
return item;
obj = obj->parent();
}
return nullptr;
}
const QQuickPopup::ClosePolicy QQuickPopupPrivate::DefaultClosePolicy = QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutside;
QQuickPopupPrivate::QQuickPopupPrivate()
: transitionManager(this)
{
}
void QQuickPopupPrivate::init()
{
Q_Q(QQuickPopup);
popupItem = new QQuickPopupItem(q);
popupItem->setVisible(false);
QObject::connect(popupItem, &QQuickControl::paddingChanged, q, &QQuickPopup::paddingChanged);
QObject::connect(popupItem, &QQuickControl::backgroundChanged, q, &QQuickPopup::backgroundChanged);
QObject::connect(popupItem, &QQuickControl::contentItemChanged, q, &QQuickPopup::contentItemChanged);
QObject::connect(popupItem, &QQuickControl::implicitContentWidthChanged, q, &QQuickPopup::implicitContentWidthChanged);
QObject::connect(popupItem, &QQuickControl::implicitContentHeightChanged, q, &QQuickPopup::implicitContentHeightChanged);
QObject::connect(popupItem, &QQuickControl::implicitBackgroundWidthChanged, q, &QQuickPopup::implicitBackgroundWidthChanged);
QObject::connect(popupItem, &QQuickControl::implicitBackgroundHeightChanged, q, &QQuickPopup::implicitBackgroundHeightChanged);
}
void QQuickPopupPrivate::closeOrReject()
{
Q_Q(QQuickPopup);
#if QT_CONFIG(quicktemplates2_container)
if (QQuickDialog *dialog = qobject_cast<QQuickDialog*>(q))
dialog->reject();
else
#endif
q->close();
touchId = -1;
}
bool QQuickPopupPrivate::tryClose(const QPointF &pos, QQuickPopup::ClosePolicy flags)
{
if (!interactive)
return false;
static const QQuickPopup::ClosePolicy outsideFlags = QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnReleaseOutside;
static const QQuickPopup::ClosePolicy outsideParentFlags = QQuickPopup::CloseOnPressOutsideParent | QQuickPopup::CloseOnReleaseOutsideParent;
const bool onOutside = closePolicy & (flags & outsideFlags);
const bool onOutsideParent = closePolicy & (flags & outsideParentFlags);
if ((onOutside && outsidePressed) || (onOutsideParent && outsideParentPressed)) {
if (!contains(pos) && (!dimmer || dimmer->contains(dimmer->mapFromScene(pos)))) {
if (!onOutsideParent || !parentItem || !parentItem->contains(parentItem->mapFromScene(pos))) {
closeOrReject();
return true;
}
}
}
return false;
}
bool QQuickPopupPrivate::contains(const QPointF &scenePos) const
{
return popupItem->contains(popupItem->mapFromScene(scenePos));
}
#if QT_CONFIG(quicktemplates2_multitouch)
bool QQuickPopupPrivate::acceptTouch(const QTouchEvent::TouchPoint &point)
{
if (point.id() == touchId)
return true;
if (touchId == -1 && point.state() != QEventPoint::Released) {
touchId = point.id();
return true;
}
return false;
}
#endif
bool QQuickPopupPrivate::blockInput(QQuickItem *item, const QPointF &point) const
{
// don't propagate events within the popup beyond the overlay
if (popupItem->contains(popupItem->mapFromScene(point))
&& item == QQuickOverlay::overlay(window)) {
return true;
}
// don't block presses and releases
// a) outside a non-modal popup,
// b) to popup children/content, or
// c) outside a modal popups's background dimming
return modal && ((popupItem != item) && !popupItem->isAncestorOf(item)) && (!dimmer || dimmer->contains(dimmer->mapFromScene(point)));
}
bool QQuickPopupPrivate::handlePress(QQuickItem *item, const QPointF &point, ulong timestamp)
{
Q_UNUSED(timestamp);
pressPoint = point;
outsidePressed = !contains(point);
if (outsidePressed && parentItem) {
// Note that the parentItem (e.g a menuBarItem, in case of a MenuBar) will
// live inside another window when using popup windows. We therefore need to
// map to and from global.
const QPointF globalPoint = item->mapToGlobal(point);
const QPointF localPoint = parentItem->mapFromGlobal(globalPoint);
outsideParentPressed = !parentItem->contains(localPoint);
}
tryClose(point, QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnPressOutsideParent);
return blockInput(item, point);
}
bool QQuickPopupPrivate::handleMove(QQuickItem *item, const QPointF &point, ulong timestamp)
{
Q_UNUSED(timestamp);
return blockInput(item, point);
}
bool QQuickPopupPrivate::handleRelease(QQuickItem *item, const QPointF &point, ulong timestamp)
{
Q_UNUSED(timestamp);
if (item != popupItem && !contains(pressPoint))
tryClose(point, QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent);
pressPoint = QPointF();
outsidePressed = false;
outsideParentPressed = false;
touchId = -1;
return blockInput(item, point);
}
void QQuickPopupPrivate::handleUngrab()
{
Q_Q(QQuickPopup);
QQuickOverlay *overlay = QQuickOverlay::overlay(window);
if (overlay) {
QQuickOverlayPrivate *p = QQuickOverlayPrivate::get(overlay);
if (p->mouseGrabberPopup == q)
p->mouseGrabberPopup = nullptr;
}
pressPoint = QPointF();
touchId = -1;
}
bool QQuickPopupPrivate::handleMouseEvent(QQuickItem *item, QMouseEvent *event)
{
switch (event->type()) {
case QEvent::MouseButtonPress:
return handlePress(item, event->scenePosition(), event->timestamp());
case QEvent::MouseMove:
return handleMove(item, event->scenePosition(), event->timestamp());
case QEvent::MouseButtonRelease:
return handleRelease(item, event->scenePosition(), event->timestamp());
default:
Q_UNREACHABLE_RETURN(false);
}
}
bool QQuickPopupPrivate::handleHoverEvent(QQuickItem *item, QHoverEvent *event)
{
switch (event->type()) {
case QEvent::HoverEnter:
case QEvent::HoverMove:
case QEvent::HoverLeave:
return blockInput(item, event->scenePosition());
default:
Q_UNREACHABLE_RETURN(false);
}
}
QMarginsF QQuickPopupPrivate::windowInsets() const
{
Q_Q(const QQuickPopup);
// If the popup has negative insets, it means that its background is pushed
// outside the bounds of the popup. This is fine when the popup is an item in the
// scene (Popup.Item), but will result in the background being clipped when using
// a window (Popup.Window). To avoid this, the window will been made bigger than
// the popup (according to the insets), to also include the part that ends up
// outside (which is usually a drop-shadow).
// Note that this also means that we need to take those extra margins into account
// whenever we resize or position the menu, so that the top-left of the popup ends
// up at the requested position, and not the top-left of the window.
const auto *popupItemPrivate = QQuickControlPrivate::get(popupItem);
if (!usePopupWindow() || (popupItemPrivate->background.isExecuting() && popupItemPrivate->background->clip())) {
// Items in the scene are allowed to draw out-of-bounds, so we don't
// need to do anything if we're not using popup windows. The same is
// also true for popup windows if the background is clipped.
return {0, 0, 0, 0};
}
return {
q->leftInset() < 0 ? -q->leftInset() : 0,
q->rightInset() < 0 ? -q->rightInset() : 0,
q->topInset() < 0 ? -q->topInset() : 0,
q->bottomInset() < 0 ? -q->bottomInset() : 0
};
}
QPointF QQuickPopupPrivate::windowInsetsTopLeft() const
{
const QMarginsF windowMargins = windowInsets();
return {windowMargins.left(), windowMargins.top()};
}
void QQuickPopupPrivate::setEffectivePosFromWindowPos(const QPointF &windowPos)
{
// Popup operates internally with three different positions; requested
// position, effective position, and window position. The first is the
// position requested by the application, and the second is where the popup
// is actually placed. The reason for placing it on a different position than
// the one requested, is to keep it inside the window (in case of Popup.Item),
// or the screen (in case of Popup.Window).
// Additionally, since a popup can set Qt::FramelessWindowHint and draw the
// window frame from the background delegate, the effective position in that
// case is adjusted to be the top-left corner of the background delegate, rather
// than the top-left corner of the window. This allowes the background delegate
// to render a drop-shadow between the edge of the window and the background frame.
// Finally, the window position is the actual position of the window, including
// any drop-shadow effects. This posision can be calculated by taking
// the effective position and subtract the dropShadowOffset().
Q_Q(QQuickPopup);
const QPointF oldEffectivePos = effectivePos;
effectivePos = windowPos + windowInsetsTopLeft();
if (!qFuzzyCompare(oldEffectivePos.x(), effectivePos.x()))
emit q->xChanged();
if (!qFuzzyCompare(oldEffectivePos.y(), effectivePos.y()))
emit q->yChanged();
}
#if QT_CONFIG(quicktemplates2_multitouch)
bool QQuickPopupPrivate::handleTouchEvent(QQuickItem *item, QTouchEvent *event)
{
switch (event->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
for (const QTouchEvent::TouchPoint &point : event->points()) {
if (event->type() != QEvent::TouchEnd && !acceptTouch(point))
return blockInput(item, point.position());
switch (point.state()) {
case QEventPoint::Pressed:
return handlePress(item, item->mapToScene(point.position()), event->timestamp());
case QEventPoint::Updated:
return handleMove(item, item->mapToScene(point.position()), event->timestamp());
case QEventPoint::Released:
return handleRelease(item, item->mapToScene(point.position()), event->timestamp());
default:
break;
}
}
break;
case QEvent::TouchCancel:
handleUngrab();
break;
default:
break;
}
return false;
}
#endif
bool QQuickPopupPrivate::prepareEnterTransition()
{
Q_Q(QQuickPopup);
if (!window) {
qmlWarning(q) << "cannot find any window to open popup in.";
return false;
}
if (transitionState == EnterTransition && transitionManager.isRunning())
return false;
if (transitionState != EnterTransition) {
const QPointer<QQuickItem> lastActiveFocusItem = window->activeFocusItem();
visible = true;
adjustPopupItemParentAndWindow();
if (dim)
createOverlay();
showDimmer();
emit q->aboutToShow();
transitionState = EnterTransition;
getPositioner()->setParentItem(parentItem);
emit q->visibleChanged();
if (lastActiveFocusItem) {
if (auto *overlay = QQuickOverlay::overlay(window)) {
auto *overlayPrivate = QQuickOverlayPrivate::get(overlay);
if (overlayPrivate->lastActiveFocusItem.isNull() && !popupItem->isAncestorOf(lastActiveFocusItem)) {
overlayPrivate->lastActiveFocusItem = lastActiveFocusItem;
savedLastActiveFocusItem = true;
}
}
}
if (focus)
popupItem->setFocus(true, Qt::PopupFocusReason);
}
return true;
}
bool QQuickPopupPrivate::prepareExitTransition()
{
Q_Q(QQuickPopup);
if (transitionState == ExitTransition && transitionManager.isRunning())
return false;
Q_ASSERT(popupItem);
// We need to cache the original scale and opacity values so we can reset it after
// the exit transition is done so they have the original values again
prevScale = popupItem->scale();
prevOpacity = popupItem->opacity();
if (transitionState != ExitTransition) {
// The setFocus(false) call below removes any active focus before we're
// able to check it in finalizeExitTransition.
if (!hadActiveFocusBeforeExitTransition) {
const auto *da = QQuickItemPrivate::get(popupItem)->deliveryAgentPrivate();
hadActiveFocusBeforeExitTransition = popupItem->hasActiveFocus() || (da && da->focusTargetItem() == popupItem);
}
if (focus)
popupItem->setFocus(false, Qt::PopupFocusReason);
transitionState = ExitTransition;
hideDimmer();
emit q->aboutToHide();
emit q->openedChanged();
}
return true;
}
void QQuickPopupPrivate::finalizeEnterTransition()
{
Q_Q(QQuickPopup);
transitionState = NoTransition;
reposition();
emit q->openedChanged();
opened();
}
void QQuickPopupPrivate::finalizeExitTransition()
{
Q_Q(QQuickPopup);
getPositioner()->setParentItem(nullptr);
if (popupItem) {
popupItem->setParentItem(nullptr);
popupItem->setVisible(false);
}
destroyDimmer();
if (auto *overlay = QQuickOverlay::overlay(window)) {
auto *overlayPrivate = QQuickOverlayPrivate::get(overlay);
// restore focus to the next popup in chain, or to the window content if there are no other popups open
if (hadActiveFocusBeforeExitTransition) {
QQuickPopup *nextFocusPopup = nullptr;
const auto stackingOrderPopups = overlayPrivate->stackingOrderPopups();
for (auto popup : stackingOrderPopups) {
// only pick a popup that is focused but has not already been activated
if (QQuickPopupPrivate::get(popup)->transitionState != ExitTransition
&& popup->hasFocus() && !popup->hasActiveFocus()) {
nextFocusPopup = popup;
break;
}
}
if (nextFocusPopup) {
nextFocusPopup->forceActiveFocus(Qt::PopupFocusReason);
} else {
auto *appWindow = qobject_cast<QQuickApplicationWindow*>(window);
auto *contentItem = appWindow ? appWindow->contentItem() : window->contentItem();
if (!contentItem->scopedFocusItem()
&& !overlayPrivate->lastActiveFocusItem.isNull()) {
// The last active focus item may have lost focus not just for
// itself but for its entire focus chain, so force active focus.
overlayPrivate->lastActiveFocusItem->forceActiveFocus(Qt::OtherFocusReason);
} else {
contentItem->setFocus(true, Qt::PopupFocusReason);
}
}
}
// Clear the overlay's saved focus if this popup was the one that set it
if (savedLastActiveFocusItem)
overlayPrivate->lastActiveFocusItem = nullptr;
}
visible = false;
adjustPopupItemParentAndWindow();
transitionState = NoTransition;
hadActiveFocusBeforeExitTransition = false;
savedLastActiveFocusItem = false;
emit q->visibleChanged();
emit q->closed();
#if QT_CONFIG(accessibility)
const auto type = q->effectiveAccessibleRole() == QAccessible::PopupMenu
? QAccessible::PopupMenuEnd
: QAccessible::DialogEnd;
QAccessibleEvent ev(q->popupItem(), type);
QAccessible::updateAccessibility(&ev);
#endif
if (popupItem) {
popupItem->setScale(prevScale);
popupItem->setOpacity(prevOpacity);
}
}
void QQuickPopupPrivate::opened()
{
Q_Q(QQuickPopup);
emit q->opened();
#if QT_CONFIG(accessibility)
const auto type = q->effectiveAccessibleRole() == QAccessible::PopupMenu
? QAccessible::PopupMenuStart
: QAccessible::DialogStart;
QAccessibleEvent ev(q->popupItem(), type);
QAccessible::updateAccessibility(&ev);
#endif
}
Qt::WindowFlags QQuickPopupPrivate::popupWindowType() const
{
return Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint;
}
QMarginsF QQuickPopupPrivate::getMargins() const
{
Q_Q(const QQuickPopup);
return QMarginsF(q->leftMargin(), q->topMargin(), q->rightMargin(), q->bottomMargin());
}
void QQuickPopupPrivate::setTopMargin(qreal value, bool reset)
{
Q_Q(QQuickPopup);
qreal oldMargin = q->topMargin();
topMargin = value;
hasTopMargin = !reset;
if ((!reset && !qFuzzyCompare(oldMargin, value)) || (reset && !qFuzzyCompare(oldMargin, margins))) {
emit q->topMarginChanged();
q->marginsChange(QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin),
QMarginsF(leftMargin, oldMargin, rightMargin, bottomMargin));
}
}
void QQuickPopupPrivate::setLeftMargin(qreal value, bool reset)
{
Q_Q(QQuickPopup);
qreal oldMargin = q->leftMargin();
leftMargin = value;
hasLeftMargin = !reset;
if ((!reset && !qFuzzyCompare(oldMargin, value)) || (reset && !qFuzzyCompare(oldMargin, margins))) {
emit q->leftMarginChanged();
q->marginsChange(QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin),
QMarginsF(oldMargin, topMargin, rightMargin, bottomMargin));
}
}
void QQuickPopupPrivate::setRightMargin(qreal value, bool reset)
{
Q_Q(QQuickPopup);
qreal oldMargin = q->rightMargin();
rightMargin = value;
hasRightMargin = !reset;
if ((!reset && !qFuzzyCompare(oldMargin, value)) || (reset && !qFuzzyCompare(oldMargin, margins))) {
emit q->rightMarginChanged();
q->marginsChange(QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin),
QMarginsF(leftMargin, topMargin, oldMargin, bottomMargin));
}
}
void QQuickPopupPrivate::setBottomMargin(qreal value, bool reset)
{
Q_Q(QQuickPopup);
qreal oldMargin = q->bottomMargin();
bottomMargin = value;
hasBottomMargin = !reset;
if ((!reset && !qFuzzyCompare(oldMargin, value)) || (reset && !qFuzzyCompare(oldMargin, margins))) {
emit q->bottomMarginChanged();
q->marginsChange(QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin),
QMarginsF(leftMargin, topMargin, rightMargin, oldMargin));
}
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty Item QtQuick.Controls::Popup::anchors.centerIn
Anchors provide a way to position an item by specifying its
relationship with other items.
A common use case is to center a popup within its parent. One way to do
this is with the \l[QtQuick]{Item::}{x} and \l[QtQuick]{Item::}{y} properties. Anchors offer
a more convenient approach:
\qml
Pane {
// ...
Popup {
anchors.centerIn: parent
}
}
\endqml
It is also possible to center the popup in the window by using \l Overlay:
\snippet qtquickcontrols-popup.qml centerIn
This makes it easy to center a popup in the window from any component.
\note Popups can only be centered within their immediate parent or
the window overlay; trying to center in other items will produce a warning.
\sa {Popup Positioning}, {Item::}{anchors}, {Using Qt Quick Controls types
in property declarations}
*/
QQuickPopupAnchors *QQuickPopupPrivate::getAnchors()
{
Q_Q(QQuickPopup);
if (!anchors)
anchors = new QQuickPopupAnchors(q);
return anchors;
}
QQuickPopupPositioner *QQuickPopupPrivate::getPositioner()
{
Q_Q(QQuickPopup);
if (!positioner)
positioner = new QQuickPopupPositioner(q);
return positioner;
}
void QQuickPopupPrivate::setWindow(QQuickWindow *newWindow)
{
Q_Q(QQuickPopup);
if (window == newWindow)
return;
if (window) {
QQuickOverlay *overlay = QQuickOverlay::overlay(window);
if (overlay)
QQuickOverlayPrivate::get(overlay)->removePopup(q);
}
window = newWindow;
if (newWindow) {
QQuickOverlay *overlay = QQuickOverlay::overlay(newWindow);
if (overlay)
QQuickOverlayPrivate::get(overlay)->addPopup(q);
QQuickControlPrivate *p = QQuickControlPrivate::get(popupItem);
p->resolveFont();
if (QQuickApplicationWindow *appWindow = qobject_cast<QQuickApplicationWindow *>(newWindow))
p->updateLocale(appWindow->locale(), false); // explicit=false
}
emit q->windowChanged(newWindow);
if (complete && visible && window)
transitionManager.transitionEnter();
}
void QQuickPopupPrivate::itemDestroyed(QQuickItem *item)
{
Q_Q(QQuickPopup);
if (item == parentItem)
q->setParentItem(nullptr);
}
void QQuickPopupPrivate::reposition()
{
getPositioner()->reposition();
}
QPalette QQuickPopupPrivate::defaultPalette() const
{
return QQuickTheme::palette(QQuickTheme::System);
}
QQuickPopup::PopupType QQuickPopupPrivate::resolvedPopupType() const
{
// Whether or not the resolved popup type ends up the same as the preferred popup type
// depends on platform capabilities, the popup subclass, and sometimes also the location
// of the popup in the parent hierarchy (menus). This function can therefore be overridden
// to return the actual popup type that should be used, based on the knowledge the popup
// has just before it's about to be shown.
// PopupType::Native is not directly supported by QQuickPopup (only by subclasses).
// So for that case, we fall back to use PopupType::Window, if supported.
if (popupType == QQuickPopup::PopupType::Window
|| popupType == QQuickPopup::PopupType::Native) {
if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::Capability::MultipleWindows))
return QQuickPopup::PopupType::Window;
}
return QQuickPopup::PopupType::Item;
}
bool QQuickPopupPrivate::usePopupWindow() const
{
return resolvedPopupType() == QQuickPopup::PopupType::Window;
}
void QQuickPopupPrivate::adjustPopupItemParentAndWindow()
{
Q_Q(QQuickPopup);
QQuickOverlay *overlay = QQuickOverlay::overlay(window);
if (visible && popupWindowDirty) {
popupItem->setParentItem(overlay);
if (popupWindow) {
popupWindow->deleteLater();
popupWindow = nullptr;
}
popupWindowDirty = false;
}
if (usePopupWindow()) {
if (visible) {
if (!popupWindow) {
popupWindow = new QQuickPopupWindow(q, window);
// Changing the visual parent can cause the popup item's implicit width/height to change.
// We store the initial size here first, to ensure that we're resizing the window to the correct size.
const qreal initialWidth = popupItem->width() + windowInsets().left() + windowInsets().right();
const qreal initialHeight = popupItem->height() + windowInsets().top() + windowInsets().bottom();
popupItem->setParentItem(popupWindow->contentItem());
popupWindow->resize(initialWidth, initialHeight);
popupWindow->setModality(modal ? Qt::ApplicationModal : Qt::NonModal);
popupItem->resetTitle();
popupWindow->setTitle(title);
}
popupItem->setParentItem(popupWindow->contentItem());
popupItem->forceActiveFocus(Qt::PopupFocusReason);
}
if (popupWindow)
popupWindow->setVisible(visible);
} else {
if (visible) {
popupItem->setParentItem(overlay);
const auto popupStack = QQuickOverlayPrivate::get(overlay)->stackingOrderPopups();
// if there is a stack of popups, and the current top popup item belongs to an
// ancestor of this popup, then make sure that this popup's item is at the top
// of the stack.
const QQuickPopup *topPopup = popupStack.isEmpty() ? nullptr : popupStack.first();
const QObject *ancestor = q;
while (ancestor && topPopup) {
if (ancestor == topPopup)
break;
ancestor = ancestor->parent();
}
if (topPopup && topPopup != q && ancestor) {
QQuickItem *topPopupItem = popupStack.first()->popupItem();
popupItem->stackAfter(topPopupItem);
// If the popup doesn't have an explicit z value set, set it to be at least as
// high as the current top popup item so that later opened popups are on top.
if (!hasZ)
popupItem->setZ(qMax(topPopupItem->z(), popupItem->z()));
}
}
popupItem->setTitle(title);
}
popupItem->setVisible(visible);
}
QQuickItem *QQuickPopupPrivate::createDimmer(QQmlComponent *component, QQuickPopup *popup, QQuickItem *parent) const
{
QQuickItem *item = nullptr;
if (component) {
QQmlContext *context = component->creationContext();
if (!context)
context = qmlContext(popup);
item = qobject_cast<QQuickItem*>(component->beginCreate(context));
}
// when there is no overlay component available (with plain QQuickWindow),
// use a plain QQuickItem as a fallback to block hover events
if (!item && popup->isModal())
item = new QQuickItem;
if (item) {
item->setParentItem(parent);
if (resolvedPopupType() != QQuickPopup::PopupType::Window)
item->stackBefore(popup->popupItem());
item->setZ(popup->z());
// needed for the virtual keyboard to set a containment mask on the dimmer item
qCDebug(lcDimmer) << "dimmer" << item << "registered with" << parent;
parent->setProperty("_q_dimmerItem", QVariant::fromValue<QQuickItem*>(item));
if (popup->isModal()) {
item->setAcceptedMouseButtons(Qt::AllButtons);
#if QT_CONFIG(cursor)
item->setCursor(Qt::ArrowCursor);
#endif
#if QT_CONFIG(quicktemplates2_hover)
// TODO: switch to QStyleHints::useHoverEffects in Qt 5.8
item->setAcceptHoverEvents(true);
// item->setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects());
// connect(QGuiApplication::styleHints(), &QStyleHints::useHoverEffectsChanged, item, &QQuickItem::setAcceptHoverEvents);
#endif
}
if (component)
component->completeCreate();
}
qCDebug(lcDimmer) << "finished creating dimmer from component" << component
<< "for popup" << popup << "with parent" << parent << "- item is:" << item;
return item;
}
void QQuickPopupPrivate::createOverlay()
{
Q_Q(QQuickPopup);
QQuickOverlay *overlay = QQuickOverlay::overlay(window);
if (!overlay)
return;
QQmlComponent *component = nullptr;
QQuickOverlayAttached *overlayAttached = qobject_cast<QQuickOverlayAttached *>(qmlAttachedPropertiesObject<QQuickOverlay>(q, false));
if (overlayAttached)
component = modal ? overlayAttached->modal() : overlayAttached->modeless();
if (!component)
component = modal ? overlay->modal() : overlay->modeless();
if (!dimmer) {
dimmer = createDimmer(component, q, overlay);
if (!dimmer)
return;
// We cannot update explicitDimmerOpacity when dimmer's opacity changes,
// as it is expected to do so when we fade the dimmer in and out in
// show/hideDimmer, and any binding of the dimmer's opacity will be
// implicitly broken anyway.
explicitDimmerOpacity = dimmer->opacity();
// initially fully transparent, showDimmer fades the dimmer in.
dimmer->setOpacity(0);
if (q->isVisible())
showDimmer();
}
resizeDimmer();
}
void QQuickPopupPrivate::destroyDimmer()
{
if (dimmer) {
qCDebug(lcDimmer) << "destroying dimmer" << dimmer;
if (QObject *dimmerParentItem = dimmer->parentItem()) {
if (dimmerParentItem->property("_q_dimmerItem").value<QQuickItem*>() == dimmer)
dimmerParentItem->setProperty("_q_dimmerItem", QVariant());
}
dimmer->setParentItem(nullptr);
dimmer->deleteLater();
dimmer = nullptr;
}
}
void QQuickPopupPrivate::toggleOverlay()
{
destroyDimmer();
if (dim)
createOverlay();
}
void QQuickPopupPrivate::updateContentPalettes(const QPalette& parentPalette)
{
// Inherit parent palette to all child objects
if (providesPalette())
inheritPalette(parentPalette);
// Inherit parent palette to items within popup (such as headers and footers)
QQuickItemPrivate::get(popupItem)->updateChildrenPalettes(parentPalette);
}
void QQuickPopupPrivate::updateChildrenPalettes(const QPalette& parentPalette)
{
updateContentPalettes(parentPalette);
}
void QQuickPopupPrivate::showDimmer()
{
// use QQmlProperty instead of QQuickItem::setOpacity() to trigger QML Behaviors
if (dim && dimmer)
QQmlProperty::write(dimmer, QStringLiteral("opacity"), explicitDimmerOpacity);
}
void QQuickPopupPrivate::hideDimmer()
{
// use QQmlProperty instead of QQuickItem::setOpacity() to trigger QML Behaviors
if (dim && dimmer)
QQmlProperty::write(dimmer, QStringLiteral("opacity"), 0.0);
}
void QQuickPopupPrivate::resizeDimmer()
{
if (!dimmer)
return;
const QQuickOverlay *overlay = QQuickOverlay::overlay(window);
qreal w = overlay ? overlay->width() : 0;
qreal h = overlay ? overlay->height() : 0;
dimmer->setSize(QSizeF(w, h));
}
QQuickPopupTransitionManager::QQuickPopupTransitionManager(QQuickPopupPrivate *popup)
: popup(popup)
{
}
void QQuickPopupTransitionManager::transitionEnter()
{
if (popup->transitionState == QQuickPopupPrivate::ExitTransition)
cancel();
if (!popup->prepareEnterTransition())
return;
if (popup->window)
transition(popup->enterActions, popup->enter, popup->q_func());
else
finished();
}
void QQuickPopupTransitionManager::transitionExit()
{
if (!popup->prepareExitTransition())
return;
if (popup->window)
transition(popup->exitActions, popup->exit, popup->q_func());
else
finished();
}
void QQuickPopupTransitionManager::finished()
{
if (popup->transitionState == QQuickPopupPrivate::EnterTransition)
popup->finalizeEnterTransition();
else if (popup->transitionState == QQuickPopupPrivate::ExitTransition)
popup->finalizeExitTransition();
}
QQuickPopup::QQuickPopup(QObject *parent)
: QObject(*(new QQuickPopupPrivate), parent)
{
Q_D(QQuickPopup);
d->init();
// By default, allow popup to move beyond window edges
d->relaxEdgeConstraint = true;
}
QQuickPopup::QQuickPopup(QQuickPopupPrivate &dd, QObject *parent)
: QObject(dd, parent)
{
Q_D(QQuickPopup);
d->init();
}
QQuickPopup::~QQuickPopup()
{
Q_D(QQuickPopup);
d->inDestructor = true;
QQuickItem *currentContentItem = d->popupItem->d_func()->contentItem.data();
if (currentContentItem) {
disconnect(currentContentItem, &QQuickItem::childrenChanged,
this, &QQuickPopup::contentChildrenChanged);
}
setParentItem(nullptr);
// If the popup is destroyed before the exit transition finishes,
// the necessary cleanup (removing modal dimmers that block mouse events,
// emitting closed signal, etc.) won't happen. That's why we do it manually here.
if (d->transitionState == QQuickPopupPrivate::ExitTransition && d->transitionManager.isRunning())
d->finalizeExitTransition();
delete d->popupItem;
d->popupItem = nullptr;
delete d->positioner;
d->positioner = nullptr;
if (d->popupWindow)
delete d->popupWindow;
d->popupWindow = nullptr;
}
/*!
\qmlmethod void QtQuick.Controls::Popup::open()
Opens the popup.
\sa visible
*/
void QQuickPopup::open()
{
setVisible(true);
}
/*!
\qmlmethod void QtQuick.Controls::Popup::close()
Closes the popup.
\sa visible
*/
void QQuickPopup::close()
{
setVisible(false);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::x
This property holds the x-coordinate of the popup.
\sa y, z
*/
qreal QQuickPopup::x() const
{
return d_func()->effectivePos.x();
}
void QQuickPopup::setX(qreal x)
{
Q_D(QQuickPopup);
setPosition(QPointF(x, d->y));
}
/*!
\qmlproperty real QtQuick.Controls::Popup::y
This property holds the y-coordinate of the popup.
\sa x, z
*/
qreal QQuickPopup::y() const
{
return d_func()->effectivePos.y();
}
void QQuickPopup::setY(qreal y)
{
Q_D(QQuickPopup);
setPosition(QPointF(d->x, y));
}
QPointF QQuickPopup::position() const
{
return d_func()->effectivePos;
}
void QQuickPopup::setPosition(const QPointF &pos)
{
Q_D(QQuickPopup);
const bool xChange = !qFuzzyCompare(d->x, pos.x());
const bool yChange = !qFuzzyCompare(d->y, pos.y());
if (!xChange && !yChange)
return;
d->x = pos.x();
d->y = pos.y();
if (d->popupItem->isVisible()) {
d->reposition();
} else {
if (xChange)
emit xChanged();
if (yChange)
emit yChanged();
}
}
/*!
\qmlproperty real QtQuick.Controls::Popup::z
This property holds the z-value of the popup. Z-value determines
the stacking order of popups.
If two visible popups have the same z-value, the last one that
was opened will be on top.
If a popup has no explicitly set z-value when opened, and is a child
of an already open popup, then it will be stacked on top of its parent.
This ensures that children are never hidden under their parents.
If the popup has its own window, the z-value will determine the window
stacking order instead.
The default z-value is \c 0.
\sa x, y
*/
qreal QQuickPopup::z() const
{
Q_D(const QQuickPopup);
return d->popupItem->z();
}
void QQuickPopup::setZ(qreal z)
{
Q_D(QQuickPopup);
d->hasZ = true;
bool previousZ = d->popupWindow ? d->popupWindow->z() : d->popupItem->z();
if (qFuzzyCompare(z, previousZ))
return;
if (d->popupWindow)
d->popupWindow->setZ(z);
else
d->popupItem->setZ(z);
emit zChanged();
}
void QQuickPopup::resetZ()
{
Q_D(QQuickPopup);
setZ(0);
d->hasZ = false;
}
/*!
\qmlproperty real QtQuick.Controls::Popup::width
This property holds the width of the popup.
*/
qreal QQuickPopup::width() const
{
Q_D(const QQuickPopup);
return d->popupItem->width();
}
void QQuickPopup::setWidth(qreal width)
{
Q_D(QQuickPopup);
d->hasWidth = true;
// QQuickPopupWindow::setWidth() triggers a window resize event.
// This will cause QQuickPopupWindow::resizeEvent() to resize
// the popupItem. QQuickPopupItem::geometryChanged() calls QQuickPopup::geometryChange(),
// which emits widthChanged().
if (d->popupWindow)
d->popupWindow->setWidth(width + d->windowInsets().left() + d->windowInsets().right());
else
d->popupItem->setWidth(width);
}
void QQuickPopup::resetWidth()
{
Q_D(QQuickPopup);
if (!d->hasWidth)
return;
d->hasWidth = false;
d->popupItem->resetWidth();
if (d->popupItem->isVisible())
d->reposition();
}
/*!
\qmlproperty real QtQuick.Controls::Popup::height
This property holds the height of the popup.
*/
qreal QQuickPopup::height() const
{
Q_D(const QQuickPopup);
return d->popupItem->height();
}
void QQuickPopup::setHeight(qreal height)
{
Q_D(QQuickPopup);
d->hasHeight = true;
// QQuickPopupWindow::setHeight() triggers a window resize event.
// This will cause QQuickPopupWindow::resizeEvent() to resize
// the popupItem. QQuickPopupItem::geometryChanged() calls QQuickPopup::geometryChange(),
// which emits heightChanged().
if (d->popupWindow)
d->popupWindow->setHeight(height + d->windowInsets().top() + d->windowInsets().bottom());
else
d->popupItem->setHeight(height);
}
void QQuickPopup::resetHeight()
{
Q_D(QQuickPopup);
if (!d->hasHeight)
return;
d->hasHeight = false;
d->popupItem->resetHeight();
if (d->popupItem->isVisible())
d->reposition();
}
/*!
\qmlproperty real QtQuick.Controls::Popup::implicitWidth
This property holds the implicit width of the popup.
*/
qreal QQuickPopup::implicitWidth() const
{
Q_D(const QQuickPopup);
return d->popupItem->implicitWidth();
}
void QQuickPopup::setImplicitWidth(qreal width)
{
Q_D(QQuickPopup);
d->popupItem->setImplicitWidth(width);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::implicitHeight
This property holds the implicit height of the popup.
*/
qreal QQuickPopup::implicitHeight() const
{
Q_D(const QQuickPopup);
return d->popupItem->implicitHeight();
}
void QQuickPopup::setImplicitHeight(qreal height)
{
Q_D(QQuickPopup);
d->popupItem->setImplicitHeight(height);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::contentWidth
This property holds the content width. It is used for calculating the
total implicit width of the Popup.
For more information, see \l {Popup Sizing}.
\sa contentHeight
*/
qreal QQuickPopup::contentWidth() const
{
Q_D(const QQuickPopup);
return d->popupItem->contentWidth();
}
void QQuickPopup::setContentWidth(qreal width)
{
Q_D(QQuickPopup);
d->popupItem->setContentWidth(width);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::contentHeight
This property holds the content height. It is used for calculating the
total implicit height of the Popup.
For more information, see \l {Popup Sizing}.
\sa contentWidth
*/
qreal QQuickPopup::contentHeight() const
{
Q_D(const QQuickPopup);
return d->popupItem->contentHeight();
}
void QQuickPopup::setContentHeight(qreal height)
{
Q_D(QQuickPopup);
d->popupItem->setContentHeight(height);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::availableWidth
\readonly
This property holds the width available to the \l contentItem after
deducting horizontal padding from the \l {Item::}{width} of the popup.
\sa padding, leftPadding, rightPadding
*/
qreal QQuickPopup::availableWidth() const
{
Q_D(const QQuickPopup);
return d->popupItem->availableWidth();
}
/*!
\qmlproperty real QtQuick.Controls::Popup::availableHeight
\readonly
This property holds the height available to the \l contentItem after
deducting vertical padding from the \l {Item::}{height} of the popup.
\sa padding, topPadding, bottomPadding
*/
qreal QQuickPopup::availableHeight() const
{
Q_D(const QQuickPopup);
return d->popupItem->availableHeight();
}
/*!
\since QtQuick.Controls 2.1 (Qt 5.8)
\qmlproperty real QtQuick.Controls::Popup::spacing
This property holds the spacing.
Spacing is useful for popups that have multiple or repetitive building
blocks. For example, some styles use spacing to determine the distance
between the header, content, and footer of \l Dialog. Spacing is not
enforced by Popup, so each style may interpret it differently, and some
may ignore it altogether.
*/
qreal QQuickPopup::spacing() const
{
Q_D(const QQuickPopup);
return d->popupItem->spacing();
}
void QQuickPopup::setSpacing(qreal spacing)
{
Q_D(QQuickPopup);
d->popupItem->setSpacing(spacing);
}
void QQuickPopup::resetSpacing()
{
setSpacing(0);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::margins
This property holds the distance between the edges of the popup and the
edges of its window.
A popup with negative margins is not pushed within the bounds
of the enclosing window. The default value is \c -1.
\sa topMargin, leftMargin, rightMargin, bottomMargin, {Popup Layout}
*/
qreal QQuickPopup::margins() const
{
Q_D(const QQuickPopup);
return d->margins;
}
void QQuickPopup::setMargins(qreal margins)
{
Q_D(QQuickPopup);
if (qFuzzyCompare(d->margins, margins))
return;
QMarginsF oldMargins(leftMargin(), topMargin(), rightMargin(), bottomMargin());
d->margins = margins;
emit marginsChanged();
QMarginsF newMargins(leftMargin(), topMargin(), rightMargin(), bottomMargin());
if (!qFuzzyCompare(newMargins.top(), oldMargins.top()))
emit topMarginChanged();
if (!qFuzzyCompare(newMargins.left(), oldMargins.left()))
emit leftMarginChanged();
if (!qFuzzyCompare(newMargins.right(), oldMargins.right()))
emit rightMarginChanged();
if (!qFuzzyCompare(newMargins.bottom(), oldMargins.bottom()))
emit bottomMarginChanged();
marginsChange(newMargins, oldMargins);
}
void QQuickPopup::resetMargins()
{
setMargins(-1);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::topMargin
This property holds the distance between the top edge of the popup and
the top edge of its window.
A popup with a negative top margin is not pushed within the top edge
of the enclosing window. The default value is \c -1.
\sa margins, bottomMargin, {Popup Layout}
*/
qreal QQuickPopup::topMargin() const
{
Q_D(const QQuickPopup);
if (d->hasTopMargin)
return d->topMargin;
return d->margins;
}
void QQuickPopup::setTopMargin(qreal margin)
{
Q_D(QQuickPopup);
d->setTopMargin(margin);
}
void QQuickPopup::resetTopMargin()
{
Q_D(QQuickPopup);
d->setTopMargin(-1, true);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::leftMargin
This property holds the distance between the left edge of the popup and
the left edge of its window.
A popup with a negative left margin is not pushed within the left edge
of the enclosing window. The default value is \c -1.
\sa margins, rightMargin, {Popup Layout}
*/
qreal QQuickPopup::leftMargin() const
{
Q_D(const QQuickPopup);
if (d->hasLeftMargin)
return d->leftMargin;
return d->margins;
}
void QQuickPopup::setLeftMargin(qreal margin)
{
Q_D(QQuickPopup);
d->setLeftMargin(margin);
}
void QQuickPopup::resetLeftMargin()
{
Q_D(QQuickPopup);
d->setLeftMargin(-1, true);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::rightMargin
This property holds the distance between the right edge of the popup and
the right edge of its window.
A popup with a negative right margin is not pushed within the right edge
of the enclosing window. The default value is \c -1.
\sa margins, leftMargin, {Popup Layout}
*/
qreal QQuickPopup::rightMargin() const
{
Q_D(const QQuickPopup);
if (d->hasRightMargin)
return d->rightMargin;
return d->margins;
}
void QQuickPopup::setRightMargin(qreal margin)
{
Q_D(QQuickPopup);
d->setRightMargin(margin);
}
void QQuickPopup::resetRightMargin()
{
Q_D(QQuickPopup);
d->setRightMargin(-1, true);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::bottomMargin
This property holds the distance between the bottom edge of the popup and
the bottom edge of its window.
A popup with a negative bottom margin is not pushed within the bottom edge
of the enclosing window. The default value is \c -1.
\sa margins, topMargin, {Popup Layout}
*/
qreal QQuickPopup::bottomMargin() const
{
Q_D(const QQuickPopup);
if (d->hasBottomMargin)
return d->bottomMargin;
return d->margins;
}
void QQuickPopup::setBottomMargin(qreal margin)
{
Q_D(QQuickPopup);
d->setBottomMargin(margin);
}
void QQuickPopup::resetBottomMargin()
{
Q_D(QQuickPopup);
d->setBottomMargin(-1, true);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::padding
This property holds the default padding.
\include qquickpopup-padding.qdocinc
\sa availableWidth, availableHeight, topPadding, leftPadding, rightPadding, bottomPadding
*/
qreal QQuickPopup::padding() const
{
Q_D(const QQuickPopup);
return d->popupItem->padding();
}
void QQuickPopup::setPadding(qreal padding)
{
Q_D(QQuickPopup);
d->popupItem->setPadding(padding);
}
void QQuickPopup::resetPadding()
{
Q_D(QQuickPopup);
d->popupItem->resetPadding();
}
/*!
\qmlproperty real QtQuick.Controls::Popup::topPadding
This property holds the top padding. Unless explicitly set, the value
is equal to \c verticalPadding.
\include qquickpopup-padding.qdocinc
\sa padding, bottomPadding, verticalPadding, availableHeight
*/
qreal QQuickPopup::topPadding() const
{
Q_D(const QQuickPopup);
return d->popupItem->topPadding();
}
void QQuickPopup::setTopPadding(qreal padding)
{
Q_D(QQuickPopup);
d->popupItem->setTopPadding(padding);
}
void QQuickPopup::resetTopPadding()
{
Q_D(QQuickPopup);
d->popupItem->resetTopPadding();
}
/*!
\qmlproperty real QtQuick.Controls::Popup::leftPadding
This property holds the left padding. Unless explicitly set, the value
is equal to \c horizontalPadding.
\include qquickpopup-padding.qdocinc
\sa padding, rightPadding, horizontalPadding, availableWidth
*/
qreal QQuickPopup::leftPadding() const
{
Q_D(const QQuickPopup);
return d->popupItem->leftPadding();
}
void QQuickPopup::setLeftPadding(qreal padding)
{
Q_D(QQuickPopup);
d->popupItem->setLeftPadding(padding);
}
void QQuickPopup::resetLeftPadding()
{
Q_D(QQuickPopup);
d->popupItem->resetLeftPadding();
}
/*!
\qmlproperty real QtQuick.Controls::Popup::rightPadding
This property holds the right padding. Unless explicitly set, the value
is equal to \c horizontalPadding.
\include qquickpopup-padding.qdocinc
\sa padding, leftPadding, horizontalPadding, availableWidth
*/
qreal QQuickPopup::rightPadding() const
{
Q_D(const QQuickPopup);
return d->popupItem->rightPadding();
}
void QQuickPopup::setRightPadding(qreal padding)
{
Q_D(QQuickPopup);
d->popupItem->setRightPadding(padding);
}
void QQuickPopup::resetRightPadding()
{
Q_D(QQuickPopup);
d->popupItem->resetRightPadding();
}
/*!
\qmlproperty real QtQuick.Controls::Popup::bottomPadding
This property holds the bottom padding. Unless explicitly set, the value
is equal to \c verticalPadding.
\include qquickpopup-padding.qdocinc
\sa padding, topPadding, verticalPadding, availableHeight
*/
qreal QQuickPopup::bottomPadding() const
{
Q_D(const QQuickPopup);
return d->popupItem->bottomPadding();
}
void QQuickPopup::setBottomPadding(qreal padding)
{
Q_D(QQuickPopup);
d->popupItem->setBottomPadding(padding);
}
void QQuickPopup::resetBottomPadding()
{
Q_D(QQuickPopup);
d->popupItem->resetBottomPadding();
}
/*!
\qmlproperty Locale QtQuick.Controls::Popup::locale
This property holds the locale of the popup.
\sa mirrored, {LayoutMirroring}{LayoutMirroring}
*/
QLocale QQuickPopup::locale() const
{
Q_D(const QQuickPopup);
return d->popupItem->locale();
}
void QQuickPopup::setLocale(const QLocale &locale)
{
Q_D(QQuickPopup);
d->popupItem->setLocale(locale);
}
void QQuickPopup::resetLocale()
{
Q_D(QQuickPopup);
d->popupItem->resetLocale();
}
/*!
\since QtQuick.Controls 2.3 (Qt 5.10)
\qmlproperty bool QtQuick.Controls::Popup::mirrored
\readonly
This property holds whether the popup is mirrored.
This property is provided for convenience. A popup is considered mirrored
when its visual layout direction is right-to-left; that is, when using a
right-to-left locale.
\sa locale, {Right-to-left User Interfaces}
*/
bool QQuickPopup::isMirrored() const
{
Q_D(const QQuickPopup);
return d->popupItem->isMirrored();
}
/*!
\qmlproperty font QtQuick.Controls::Popup::font
This property holds the font currently set for the popup.
Popup propagates explicit font properties to its children. If you change a specific
property on a popup's font, that property propagates to all of the popup's children,
overriding any system defaults for that property.
\code
Popup {
font.family: "Courier"
Column {
Label {
text: qsTr("This will use Courier...")
}
Switch {
text: qsTr("... and so will this")
}
}
}
\endcode
\sa Control::font, ApplicationWindow::font
*/
QFont QQuickPopup::font() const
{
Q_D(const QQuickPopup);
return d->popupItem->font();
}
void QQuickPopup::setFont(const QFont &font)
{
Q_D(QQuickPopup);
d->popupItem->setFont(font);
}
void QQuickPopup::resetFont()
{
Q_D(QQuickPopup);
d->popupItem->resetFont();
}
QQuickWindow *QQuickPopup::window() const
{
Q_D(const QQuickPopup);
return d->window;
}
QQuickItem *QQuickPopup::popupItem() const
{
Q_D(const QQuickPopup);
return d->popupItem;
}
/*!
\qmlproperty Item QtQuick.Controls::Popup::parent
This property holds the parent item.
*/
QQuickItem *QQuickPopup::parentItem() const
{
Q_D(const QQuickPopup);
return d->parentItem;
}
void QQuickPopup::setParentItem(QQuickItem *parent)
{
Q_D(QQuickPopup);
if (d->parentItem == parent)
return;
if (d->parentItem) {
QObjectPrivate::disconnect(d->parentItem, &QQuickItem::windowChanged, d, &QQuickPopupPrivate::setWindow);
QQuickItemPrivate::get(d->parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Destroyed);
}
d->parentItem = parent;
QQuickPopupPositioner *positioner = d->getPositioner();
if (positioner->parentItem())
positioner->setParentItem(parent);
if (parent) {
QObjectPrivate::connect(parent, &QQuickItem::windowChanged, d, &QQuickPopupPrivate::setWindow);
QQuickItemPrivate::get(d->parentItem)->addItemChangeListener(d, QQuickItemPrivate::Destroyed);
} else if (d->inDestructor) {
d->destroyDimmer();
} else {
// Reset transition manager state when its parent window destroyed
if (!d->window && d->transitionManager.isRunning()) {
if (d->transitionState == QQuickPopupPrivate::EnterTransition)
d->finalizeEnterTransition();
else if (d->transitionState == QQuickPopupPrivate::ExitTransition)
d->finalizeExitTransition();
}
// NOTE: if setParentItem is called from the dtor, this bypasses virtual dispatch and calls
// QQuickPopup::close() directly
close();
}
d->setWindow(parent ? parent->window() : nullptr);
emit parentChanged();
}
void QQuickPopup::resetParentItem()
{
if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent()))
setParentItem(window->contentItem());
else
setParentItem(findParentItem());
}
/*!
\qmlproperty Item QtQuick.Controls::Popup::background
This property holds the background item.
\note If the background item has no explicit size specified, it automatically
follows the popup's size. In most cases, there is no need to specify
width or height for a background item.
\note Most popups use the implicit size of the background item to calculate
the implicit size of the popup itself. If you replace the background item
with a custom one, you should also consider providing a sensible implicit
size for it (unless it is an item like \l Image which has its own implicit
size).
\sa {Customizing Popup}
*/
QQuickItem *QQuickPopup::background() const
{
Q_D(const QQuickPopup);
return d->popupItem->background();
}
void QQuickPopup::setBackground(QQuickItem *background)
{
Q_D(QQuickPopup);
// The __notCustomizable property won't be on "this" when the popup item's setBackground function
// is called, so it won't warn. That's why we do a check here.
QQuickControlPrivate::warnIfCustomizationNotSupported(this, background, QStringLiteral("background"));
d->popupItem->setBackground(background);
}
/*!
\qmlproperty Item QtQuick.Controls::Popup::contentItem
This property holds the content item of the popup.
The content item is the visual implementation of the popup. When the
popup is made visible, the content item is automatically reparented to
the \l {Overlay::overlay}{overlay item}.
\note The content item is automatically resized to fit within the
\l padding of the popup.
\note Most popups use the implicit size of the content item to calculate
the implicit size of the popup itself. If you replace the content item
with a custom one, you should also consider providing a sensible implicit
size for it (unless it is an item like \l Text which has its own implicit
size).
\sa {Customizing Popup}
*/
QQuickItem *QQuickPopup::contentItem() const
{
Q_D(const QQuickPopup);
return d->popupItem->contentItem();
}
void QQuickPopup::setContentItem(QQuickItem *item)
{
Q_D(QQuickPopup);
// See comment in setBackground for why we do this.
QQuickControlPrivate::warnIfCustomizationNotSupported(this, item, QStringLiteral("contentItem"));
QQuickItem *oldContentItem = d->complete ? d->popupItem->d_func()->contentItem.data()
: nullptr;
if (oldContentItem)
disconnect(oldContentItem, &QQuickItem::childrenChanged, this, &QQuickPopup::contentChildrenChanged);
d->popupItem->setContentItem(item);
if (d->complete) {
QQuickItem *newContentItem = d->popupItem->d_func()->contentItem.data();
connect(newContentItem, &QQuickItem::childrenChanged, this, &QQuickPopup::contentChildrenChanged);
if (oldContentItem != newContentItem)
emit contentChildrenChanged();
}
}
/*!
\qmlproperty list<QtObject> QtQuick.Controls::Popup::contentData
\qmldefault
This property holds the list of content data.
The list contains all objects that have been declared in QML as children
of the popup.
\note Unlike \c contentChildren, \c contentData does include non-visual QML
objects.
\sa Item::data, contentChildren
*/
QQmlListProperty<QObject> QQuickPopupPrivate::contentData()
{
QQuickControlPrivate *p = QQuickControlPrivate::get(popupItem);
if (!p->contentItem)
p->executeContentItem();
return QQmlListProperty<QObject>(popupItem->contentItem(), nullptr,
QQuickItemPrivate::data_append,
QQuickItemPrivate::data_count,
QQuickItemPrivate::data_at,
QQuickItemPrivate::data_clear);
}
/*!
\qmlproperty list<Item> QtQuick.Controls::Popup::contentChildren
This property holds the list of content children.
The list contains all items that have been declared in QML as children
of the popup.
\note Unlike \c contentData, \c contentChildren does not include non-visual
QML objects.
\sa Item::children, contentData
*/
QQmlListProperty<QQuickItem> QQuickPopupPrivate::contentChildren()
{
return QQmlListProperty<QQuickItem>(popupItem->contentItem(), nullptr,
QQuickItemPrivate::children_append,
QQuickItemPrivate::children_count,
QQuickItemPrivate::children_at,
QQuickItemPrivate::children_clear);
}
/*!
\qmlproperty bool QtQuick.Controls::Popup::clip
This property holds whether clipping is enabled. The default value is \c false.
Clipping only works when the popup isn't in its own window.
*/
bool QQuickPopup::clip() const
{
Q_D(const QQuickPopup);
return d->popupItem->clip() && !d->usePopupWindow();
}
void QQuickPopup::setClip(bool clip)
{
Q_D(QQuickPopup);
if (clip == d->popupItem->clip() || d->usePopupWindow())
return;
d->popupItem->setClip(clip);
emit clipChanged();
}
/*!
\qmlproperty bool QtQuick.Controls::Popup::focus
This property holds whether the popup wants focus.
When the popup actually receives focus, \l activeFocus will be \c true.
For more information, see \l {Keyboard Focus in Qt Quick}.
The default value is \c false.
\sa activeFocus
*/
bool QQuickPopup::hasFocus() const
{
Q_D(const QQuickPopup);
return d->focus;
}
void QQuickPopup::setFocus(bool focus)
{
Q_D(QQuickPopup);
if (d->focus == focus)
return;
d->focus = focus;
emit focusChanged();
}
/*!
\qmlproperty bool QtQuick.Controls::Popup::activeFocus
\readonly
This property holds whether the popup has active focus.
\sa focus, {Keyboard Focus in Qt Quick}
*/
bool QQuickPopup::hasActiveFocus() const
{
Q_D(const QQuickPopup);
return d->popupItem->hasActiveFocus();
}
/*!
\qmlproperty bool QtQuick.Controls::Popup::modal
This property holds whether the popup is modal.
Modal popups often have a distinctive background dimming effect defined
in \l {Overlay::modal}{Overlay.modal}, and do not allow press
or release events through to items beneath them. For example, if the user
accidentally clicks outside of a popup, any item beneath that popup at
the location of the click will not receive the event.
On desktop platforms, it is common for modal popups to be closed only when
the escape key is pressed. To achieve this behavior, set
\l closePolicy to \c Popup.CloseOnEscape. By default, \c closePolicy
is set to \c {Popup.CloseOnEscape | Popup.CloseOnPressOutside}, which
means that clicking outside of a modal popup will close it.
The default value is \c false.
\sa dim
*/
bool QQuickPopup::isModal() const
{
Q_D(const QQuickPopup);
return d->modal;
}
void QQuickPopup::setModal(bool modal)
{
Q_D(QQuickPopup);
if (d->modal == modal)
return;
d->modal = modal;
d->popupWindowDirty = true;
if (d->complete && d->visible)
d->toggleOverlay();
emit modalChanged();
if (!d->hasDim) {
setDim(modal);
d->hasDim = false;
}
}
/*!
\qmlproperty bool QtQuick.Controls::Popup::dim
This property holds whether the popup dims the background.
Unless explicitly set, this property follows the value of \l modal. To
return to the default value, set this property to \c undefined.
\sa modal, {Overlay::modeless}{Overlay.modeless}
*/
bool QQuickPopup::dim() const
{
Q_D(const QQuickPopup);
return d->dim;
}
void QQuickPopup::setDim(bool dim)
{
Q_D(QQuickPopup);
d->hasDim = true;
if (d->dim == dim)
return;
d->dim = dim;
if (d->complete && d->visible)
d->toggleOverlay();
emit dimChanged();
}
void QQuickPopup::resetDim()
{
Q_D(QQuickPopup);
if (!d->hasDim)
return;
setDim(d->modal);
d->hasDim = false;
}
/*!
\qmlproperty bool QtQuick.Controls::Popup::visible
This property holds whether the popup is visible. The default value is \c false.
\sa open(), close(), opened
*/
bool QQuickPopup::isVisible() const
{
Q_D(const QQuickPopup);
return d->visible && d->popupItem->isVisible();
}
void QQuickPopup::setVisible(bool visible)
{
Q_D(QQuickPopup);
// During an exit transition, d->visible == true until the transition has completed.
// Therefore, this guard must not return early if setting visible to true while
// d->visible is true.
if (d->visible && visible && d->transitionState != QQuickPopupPrivate::ExitTransition)
return;
if (!d->visible && !visible)
return;
if (!d->complete || (visible && !d->window)) {
d->visible = visible;
return;
}
if (visible)
d->transitionManager.transitionEnter();
else
d->transitionManager.transitionExit();
}
/*!
\since QtQuick.Controls 2.3 (Qt 5.10)
\qmlproperty bool QtQuick.Controls::Popup::enabled
This property holds whether the popup is enabled. The default value is \c true.
\sa visible, Item::enabled
*/
bool QQuickPopup::isEnabled() const
{
Q_D(const QQuickPopup);
return d->popupItem->isEnabled();
}
void QQuickPopup::setEnabled(bool enabled)
{
Q_D(QQuickPopup);
d->popupItem->setEnabled(enabled);
}
/*!
\since QtQuick.Controls 2.3 (Qt 5.10)
\qmlproperty bool QtQuick.Controls::Popup::opened
This property holds whether the popup is fully open. The popup is considered opened
when it's visible and neither the \l enter nor \l exit transitions are running.
\sa open(), close(), visible
*/
bool QQuickPopup::isOpened() const
{
Q_D(const QQuickPopup);
return d->transitionState == QQuickPopupPrivate::NoTransition && isVisible();
}
/*!
\qmlproperty real QtQuick.Controls::Popup::opacity
This property holds the opacity of the popup. Opacity is specified as a number between
\c 0.0 (fully transparent) and \c 1.0 (fully opaque). The default value is \c 1.0.
\sa visible
*/
qreal QQuickPopup::opacity() const
{
Q_D(const QQuickPopup);
return d->popupItem->opacity();
}
void QQuickPopup::setOpacity(qreal opacity)
{
Q_D(QQuickPopup);
d->popupItem->setOpacity(opacity);
}
/*!
\qmlproperty real QtQuick.Controls::Popup::scale
This property holds the scale factor of the popup. The default value is \c 1.0.
A scale of less than \c 1.0 causes the popup to be rendered at a smaller size,
and a scale greater than \c 1.0 renders the popup at a larger size. Negative
scales are not supported.
*/
qreal QQuickPopup::scale() const
{
Q_D(const QQuickPopup);
return d->popupItem->scale();
}
void QQuickPopup::setScale(qreal scale)
{
Q_D(QQuickPopup);
if (qFuzzyCompare(scale, d->popupItem->scale()))
return;
d->popupItem->setScale(scale);
emit scaleChanged();
}
/*!
\qmlproperty enumeration QtQuick.Controls::Popup::closePolicy
This property determines the circumstances under which the popup closes.
The flags can be combined to allow several ways of closing the popup.
The available values are:
\value Popup.NoAutoClose The popup will only close when manually instructed to do so.
\value Popup.CloseOnPressOutside The popup will close when the mouse is pressed outside of it.
\value Popup.CloseOnPressOutsideParent The popup will close when the mouse is pressed outside of its parent.
\value Popup.CloseOnReleaseOutside The popup will close when the mouse is released outside of it.
\value Popup.CloseOnReleaseOutsideParent The popup will close when the mouse is released outside of its parent.
\value Popup.CloseOnEscape The popup will close when the escape key is pressed while the popup
has active focus.
The \c {CloseOnPress*} and \c {CloseOnRelease*} policies only apply for events
outside of popups. That is, if there are two popups open and the first has
\c Popup.CloseOnPressOutside as its policy, clicking on the second popup will
not result in the first closing.
The default value is \c {Popup.CloseOnEscape | Popup.CloseOnPressOutside}.
\note There is a known limitation that the \c Popup.CloseOnReleaseOutside
and \c Popup.CloseOnReleaseOutsideParent policies only work with
\l modal popups.
*/
QQuickPopup::ClosePolicy QQuickPopup::closePolicy() const
{
Q_D(const QQuickPopup);
return d->closePolicy;
}
void QQuickPopup::setClosePolicy(ClosePolicy policy)
{
Q_D(QQuickPopup);
d->hasClosePolicy = true;
if (d->closePolicy == policy)
return;
d->closePolicy = policy;
emit closePolicyChanged();
}
void QQuickPopup::resetClosePolicy()
{
Q_D(QQuickPopup);
setClosePolicy(QQuickPopupPrivate::DefaultClosePolicy);
d->hasClosePolicy = false;
}
/*!
\qmlproperty enumeration QtQuick.Controls::Popup::transformOrigin
This property holds the origin point for transformations in enter and exit transitions.
Nine transform origins are available, as shown in the image below.
The default transform origin is \c Popup.Center.
\image qtquickcontrols-popup-transformorigin.png
\sa enter, exit, Item::transformOrigin
*/
QQuickPopup::TransformOrigin QQuickPopup::transformOrigin() const
{
Q_D(const QQuickPopup);
return static_cast<TransformOrigin>(d->popupItem->transformOrigin());
}
void QQuickPopup::setTransformOrigin(TransformOrigin origin)
{
Q_D(QQuickPopup);
d->popupItem->setTransformOrigin(static_cast<QQuickItem::TransformOrigin>(origin));
}
/*!
\qmlproperty Transition QtQuick.Controls::Popup::enter
This property holds the transition that is applied to the popup item
when the popup is opened and enters the screen.
The following example animates the opacity of the popup when it enters
the screen:
\code
Popup {
enter: Transition {
NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 }
}
}
\endcode
\sa exit
*/
QQuickTransition *QQuickPopup::enter() const
{
Q_D(const QQuickPopup);
return d->enter;
}
void QQuickPopup::setEnter(QQuickTransition *transition)
{
Q_D(QQuickPopup);
if (d->enter == transition)
return;
d->enter = transition;
emit enterChanged();
}
/*!
\qmlproperty Transition QtQuick.Controls::Popup::exit
This property holds the transition that is applied to the popup item
when the popup is closed and exits the screen.
The following example animates the opacity of the popup when it exits
the screen:
\code
Popup {
exit: Transition {
NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 }
}
}
\endcode
\sa enter
*/
QQuickTransition *QQuickPopup::exit() const
{
Q_D(const QQuickPopup);
return d->exit;
}
void QQuickPopup::setExit(QQuickTransition *transition)
{
Q_D(QQuickPopup);
if (d->exit == transition)
return;
d->exit = transition;
emit exitChanged();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::horizontalPadding
This property holds the horizontal padding. Unless explicitly set, the value
is equal to \c padding.
\include qquickpopup-padding.qdocinc
\sa padding, leftPadding, rightPadding, verticalPadding
*/
qreal QQuickPopup::horizontalPadding() const
{
Q_D(const QQuickPopup);
return d->popupItem->horizontalPadding();
}
void QQuickPopup::setHorizontalPadding(qreal padding)
{
Q_D(QQuickPopup);
d->popupItem->setHorizontalPadding(padding);
}
void QQuickPopup::resetHorizontalPadding()
{
Q_D(QQuickPopup);
d->popupItem->resetHorizontalPadding();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::verticalPadding
This property holds the vertical padding. Unless explicitly set, the value
is equal to \c padding.
\include qquickpopup-padding.qdocinc
\sa padding, topPadding, bottomPadding, horizontalPadding
*/
qreal QQuickPopup::verticalPadding() const
{
Q_D(const QQuickPopup);
return d->popupItem->verticalPadding();
}
void QQuickPopup::setVerticalPadding(qreal padding)
{
Q_D(QQuickPopup);
d->popupItem->setVerticalPadding(padding);
}
void QQuickPopup::resetVerticalPadding()
{
Q_D(QQuickPopup);
d->popupItem->resetVerticalPadding();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::implicitContentWidth
\readonly
This property holds the implicit content width.
The value is calculated based on the content children.
\sa implicitContentHeight, implicitBackgroundWidth
*/
qreal QQuickPopup::implicitContentWidth() const
{
Q_D(const QQuickPopup);
return d->popupItem->implicitContentWidth();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::implicitContentHeight
\readonly
This property holds the implicit content height.
The value is calculated based on the content children.
\sa implicitContentWidth, implicitBackgroundHeight
*/
qreal QQuickPopup::implicitContentHeight() const
{
Q_D(const QQuickPopup);
return d->popupItem->implicitContentHeight();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::implicitBackgroundWidth
\readonly
This property holds the implicit background width.
The value is equal to \c {background ? background.implicitWidth : 0}.
\sa implicitBackgroundHeight, implicitContentWidth
*/
qreal QQuickPopup::implicitBackgroundWidth() const
{
Q_D(const QQuickPopup);
return d->popupItem->implicitBackgroundWidth();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::implicitBackgroundHeight
\readonly
This property holds the implicit background height.
The value is equal to \c {background ? background.implicitHeight : 0}.
\sa implicitBackgroundWidth, implicitContentHeight
*/
qreal QQuickPopup::implicitBackgroundHeight() const
{
Q_D(const QQuickPopup);
return d->popupItem->implicitBackgroundHeight();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::topInset
This property holds the top inset for the background.
\sa {Popup Layout}, bottomInset
*/
qreal QQuickPopup::topInset() const
{
Q_D(const QQuickPopup);
return d->popupItem->topInset();
}
void QQuickPopup::setTopInset(qreal inset)
{
Q_D(QQuickPopup);
d->popupItem->setTopInset(inset);
}
void QQuickPopup::resetTopInset()
{
Q_D(QQuickPopup);
d->popupItem->resetTopInset();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::leftInset
This property holds the left inset for the background.
\sa {Popup Layout}, rightInset
*/
qreal QQuickPopup::leftInset() const
{
Q_D(const QQuickPopup);
return d->popupItem->leftInset();
}
void QQuickPopup::setLeftInset(qreal inset)
{
Q_D(QQuickPopup);
d->popupItem->setLeftInset(inset);
}
void QQuickPopup::resetLeftInset()
{
Q_D(QQuickPopup);
d->popupItem->resetLeftInset();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::rightInset
This property holds the right inset for the background.
\sa {Popup Layout}, leftInset
*/
qreal QQuickPopup::rightInset() const
{
Q_D(const QQuickPopup);
return d->popupItem->rightInset();
}
void QQuickPopup::setRightInset(qreal inset)
{
Q_D(QQuickPopup);
d->popupItem->setRightInset(inset);
}
void QQuickPopup::resetRightInset()
{
Q_D(QQuickPopup);
d->popupItem->resetRightInset();
}
/*!
\since QtQuick.Controls 2.5 (Qt 5.12)
\qmlproperty real QtQuick.Controls::Popup::bottomInset
This property holds the bottom inset for the background.
\sa {Popup Layout}, topInset
*/
qreal QQuickPopup::bottomInset() const
{
Q_D(const QQuickPopup);
return d->popupItem->bottomInset();
}
void QQuickPopup::setBottomInset(qreal inset)
{
Q_D(QQuickPopup);
d->popupItem->setBottomInset(inset);
}
void QQuickPopup::resetBottomInset()
{
Q_D(QQuickPopup);
d->popupItem->resetBottomInset();
}
/*!
\qmlproperty enumeration QtQuick.Controls::Popup::popupType
\since 6.8
This property determines the type of popup that is preferred.
Available options:
\value Item The popup will be embedded into the
\l{Showing a popup as an item}{same scene as the parent},
without the use of a separate window.
\value Window The popup will be presented in a \l {Popup type}
{separate window}. If the platform doesn't support
multiple windows, \c Popup.Item will be used instead.
\value Native The popup will be native to the platform. If the
platform doesn't support native popups, \c Popup.Window
will be used instead.
Whether a popup will be able to use the preferred type depends on the platform.
\c Popup.Item is supported on all platforms, but \c Popup.Window and \c Popup.Native
are normally only supported on desktop platforms. Additionally, if a popup is a
\l Menu inside a \l {Native menu bars}{native menubar}, the menu will be native as
well. And if the menu is a sub-menu inside another menu, the parent (or root) menu
will decide the type.
The default value is usually \c Popup.Item, with some exceptions, mentioned above.
This might change in future versions of Qt, for certain styles and platforms that benefit
from using other popup types.
If you always want to use native menus for all styles on macOS, for example, you can do:
\code
Menu {
popupType: Qt.platform.os === "osx" ? Popup.Native : Popup.Window
}
\endcode
Also, if you choose to customize a popup (by for example changing any of the
delegates), you should consider setting the popup type to be \c Popup.Window
as well. This will ensure that your changes will be visible on all platforms
and for all styles. Otherwise, when native menus are being used, the delegates
will \e not be used for rendering.
\sa {Popup type}
*/
QQuickPopup::PopupType QQuickPopup::popupType() const
{
Q_D(const QQuickPopup);
return d->popupType;
}
void QQuickPopup::setPopupType(PopupType popupType)
{
Q_D(QQuickPopup);
if (d->popupType == popupType)
return;
d->popupType = popupType;
emit popupTypeChanged();
}
/*!
\since QtQuick.Controls 2.3 (Qt 5.10)
\qmlproperty palette QtQuick.Controls::Popup::palette
This property holds the palette currently set for the popup.
Popup propagates explicit palette properties to its children. If you change a specific
property on a popup's palette, that property propagates to all of the popup's children,
overriding any system defaults for that property.
\code
Popup {
palette.text: "red"
Column {
Label {
text: qsTr("This will use red color...")
}
Switch {
text: qsTr("... and so will this")
}
}
}
\endcode
\b {See also}: \l Item::palette, \l Window::palette, \l ColorGroup,
\l [QML] {Palette}
*/
bool QQuickPopup::filtersChildMouseEvents() const
{
Q_D(const QQuickPopup);
return d->popupItem->filtersChildMouseEvents();
}
void QQuickPopup::setFiltersChildMouseEvents(bool filter)
{
Q_D(QQuickPopup);
d->popupItem->setFiltersChildMouseEvents(filter);
}
/*!
\qmlmethod QtQuick.Controls::Popup::forceActiveFocus(enumeration reason = Qt.OtherFocusReason)
Forces active focus on the popup with the given \a reason.
This method sets focus on the popup and ensures that all ancestor
\l FocusScope objects in the object hierarchy are also given \l focus.
\sa activeFocus, Qt::FocusReason
*/
void QQuickPopup::forceActiveFocus(Qt::FocusReason reason)
{
Q_D(QQuickPopup);
d->popupItem->forceActiveFocus(reason);
}
void QQuickPopup::classBegin()
{
Q_D(QQuickPopup);
d->complete = false;
QQmlContext *context = qmlContext(this);
if (context)
QQmlEngine::setContextForObject(d->popupItem, context);
d->popupItem->classBegin();
}
void QQuickPopup::componentComplete()
{
Q_D(QQuickPopup);
qCDebug(lcQuickPopup) << "componentComplete" << this;
if (!parentItem())
resetParentItem();
if (d->visible && d->window)
d->transitionManager.transitionEnter();
d->complete = true;
d->popupItem->setObjectName(QQmlMetaType::prettyTypeName(this));
d->popupItem->componentComplete();
if (auto currentContentItem = d->popupItem->d_func()->contentItem.data()) {
connect(currentContentItem, &QQuickItem::childrenChanged,
this, &QQuickPopup::contentChildrenChanged);
}
}
bool QQuickPopup::isComponentComplete() const
{
Q_D(const QQuickPopup);
return d->complete;
}
bool QQuickPopup::childMouseEventFilter(QQuickItem *child, QEvent *event)
{
Q_UNUSED(child);
Q_UNUSED(event);
return false;
}
void QQuickPopup::focusInEvent(QFocusEvent *event)
{
event->accept();
}
void QQuickPopup::focusOutEvent(QFocusEvent *event)
{
event->accept();
}
void QQuickPopup::keyPressEvent(QKeyEvent *event)
{
Q_D(QQuickPopup);
if (!hasActiveFocus())
return;
#if QT_CONFIG(shortcut)
if (d->closePolicy.testFlag(QQuickPopup::CloseOnEscape)
&& (event->matches(QKeySequence::Cancel)
#if defined(Q_OS_ANDROID)
|| event->key() == Qt::Key_Back
#endif
)) {
event->accept();
if (d->interactive)
d->closeOrReject();
return;
}
#endif
if (hasActiveFocus() && (event->key() == Qt::Key_Tab || event->key() == Qt::Key_Backtab)) {
event->accept();
QQuickItemPrivate::focusNextPrev(d->popupItem, event->key() == Qt::Key_Tab);
}
}
void QQuickPopup::keyReleaseEvent(QKeyEvent *event)
{
event->accept();
}
void QQuickPopup::mousePressEvent(QMouseEvent *event)
{
Q_D(QQuickPopup);
event->setAccepted(d->handleMouseEvent(d->popupItem, event));
}
void QQuickPopup::mouseMoveEvent(QMouseEvent *event)
{
Q_D(QQuickPopup);
event->setAccepted(d->handleMouseEvent(d->popupItem, event));
}
void QQuickPopup::mouseReleaseEvent(QMouseEvent *event)
{
Q_D(QQuickPopup);
event->setAccepted(d->handleMouseEvent(d->popupItem, event));
}
void QQuickPopup::mouseDoubleClickEvent(QMouseEvent *event)
{
event->accept();
}
void QQuickPopup::mouseUngrabEvent()
{
Q_D(QQuickPopup);
d->handleUngrab();
}
/*!
\internal
Called whenever the window receives a Wheel/Hover/Mouse/Touch event,
and has an active popup (with popupType: Popup.Item) in its scene.
The purpose is to close popups when the press/release event happened outside of it,
and the closePolicy allows for it to happen.
If the function is called from childMouseEventFilter, then the return value of this
function will determine whether the event will be filtered, or delivered to \a item.
*/
bool QQuickPopup::overlayEvent(QQuickItem *item, QEvent *event)
{
Q_D(QQuickPopup);
switch (event->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::MouseMove:
case QEvent::Wheel:
if (d->modal)
event->accept();
return d->modal;
#if QT_CONFIG(quicktemplates2_multitouch)
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
return d->handleTouchEvent(item, static_cast<QTouchEvent *>(event));
#endif
case QEvent::HoverEnter:
case QEvent::HoverMove:
case QEvent::HoverLeave:
return d->handleHoverEvent(item, static_cast<QHoverEvent *>(event));
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
return d->handleMouseEvent(item, static_cast<QMouseEvent *>(event));
default:
return false;
}
}
#if QT_CONFIG(quicktemplates2_multitouch)
void QQuickPopup::touchEvent(QTouchEvent *event)
{
Q_D(QQuickPopup);
d->handleTouchEvent(d->popupItem, event);
}
void QQuickPopup::touchUngrabEvent()
{
Q_D(QQuickPopup);
d->handleUngrab();
}
#endif
#if QT_CONFIG(wheelevent)
void QQuickPopup::wheelEvent(QWheelEvent *event)
{
event->accept();
}
#endif
void QQuickPopup::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
{
Q_UNUSED(newItem);
Q_UNUSED(oldItem);
}
void QQuickPopup::contentSizeChange(const QSizeF &newSize, const QSizeF &oldSize)
{
qCDebug(lcQuickPopup) << "contentSizeChange called on" << this << "with newSize" << newSize << "oldSize" << oldSize;
if (!qFuzzyCompare(newSize.width(), oldSize.width()))
emit contentWidthChanged();
if (!qFuzzyCompare(newSize.height(), oldSize.height()))
emit contentHeightChanged();
}
void QQuickPopup::fontChange(const QFont &newFont, const QFont &oldFont)
{
Q_UNUSED(newFont);
Q_UNUSED(oldFont);
emit fontChanged();
}
void QQuickPopup::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
{
Q_D(QQuickPopup);
qCDebug(lcQuickPopup) << "geometryChange called on" << this << "with newGeometry" << newGeometry << "oldGeometry" << oldGeometry;
if (!d->usePopupWindow())
d->reposition();
if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width())) {
emit widthChanged();
emit availableWidthChanged();
}
if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height())) {
emit heightChanged();
emit availableHeightChanged();
}
}
void QQuickPopup::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &)
{
switch (change) {
case QQuickItem::ItemActiveFocusHasChanged:
emit activeFocusChanged();
break;
case QQuickItem::ItemOpacityHasChanged:
emit opacityChanged();
break;
default:
break;
}
}
void QQuickPopup::localeChange(const QLocale &newLocale, const QLocale &oldLocale)
{
Q_UNUSED(newLocale);
Q_UNUSED(oldLocale);
emit localeChanged();
}
void QQuickPopup::marginsChange(const QMarginsF &newMargins, const QMarginsF &oldMargins)
{
Q_D(QQuickPopup);
Q_UNUSED(newMargins);
Q_UNUSED(oldMargins);
d->reposition();
}
void QQuickPopup::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
{
const bool tp = !qFuzzyCompare(newPadding.top(), oldPadding.top());
const bool lp = !qFuzzyCompare(newPadding.left(), oldPadding.left());
const bool rp = !qFuzzyCompare(newPadding.right(), oldPadding.right());
const bool bp = !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom());
if (tp)
emit topPaddingChanged();
if (lp)
emit leftPaddingChanged();
if (rp)
emit rightPaddingChanged();
if (bp)
emit bottomPaddingChanged();
if (lp || rp) {
emit horizontalPaddingChanged();
emit availableWidthChanged();
}
if (tp || bp) {
emit verticalPaddingChanged();
emit availableHeightChanged();
}
}
void QQuickPopup::spacingChange(qreal newSpacing, qreal oldSpacing)
{
Q_UNUSED(newSpacing);
Q_UNUSED(oldSpacing);
emit spacingChanged();
}
void QQuickPopup::insetChange(const QMarginsF &newInset, const QMarginsF &oldInset)
{
if (!qFuzzyCompare(newInset.top(), oldInset.top()))
emit topInsetChanged();
if (!qFuzzyCompare(newInset.left(), oldInset.left()))
emit leftInsetChanged();
if (!qFuzzyCompare(newInset.right(), oldInset.right()))
emit rightInsetChanged();
if (!qFuzzyCompare(newInset.bottom(), oldInset.bottom()))
emit bottomInsetChanged();
}
QFont QQuickPopup::defaultFont() const
{
return QQuickTheme::font(QQuickTheme::System);
}
#if QT_CONFIG(accessibility)
QAccessible::Role QQuickPopup::effectiveAccessibleRole() const
{
auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, false);
auto role = QAccessible::NoRole;
if (auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
role = accessibleAttached->role();
if (role == QAccessible::NoRole)
role = accessibleRole();
return role;
}
QAccessible::Role QQuickPopup::accessibleRole() const
{
return QAccessible::Dialog;
}
void QQuickPopup::accessibilityActiveChanged(bool active)
{
Q_UNUSED(active);
}
#endif
QString QQuickPopup::accessibleName() const
{
Q_D(const QQuickPopup);
return d->popupItem->accessibleName();
}
void QQuickPopup::maybeSetAccessibleName(const QString &name)
{
Q_D(QQuickPopup);
d->popupItem->maybeSetAccessibleName(name);
}
QVariant QQuickPopup::accessibleProperty(const char *propertyName)
{
Q_D(const QQuickPopup);
return d->popupItem->accessibleProperty(propertyName);
}
bool QQuickPopup::setAccessibleProperty(const char *propertyName, const QVariant &value)
{
Q_D(QQuickPopup);
return d->popupItem->setAccessibleProperty(propertyName, value);
}
QQuickItem *QQuickPopup::safeAreaAttachmentItem()
{
return popupItem();
}
QT_END_NAMESPACE
#include "moc_qquickpopup_p.cpp"
|