Tue, 10 Dec 2024 15:46:34 +0100
Updated copyright for 2025.
10248 | 1 | # -*- coding: utf-8 -*- |
2 | ||
11090
f5f5f5803935
Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
3 | # Copyright (c) 2023 - 2025 Detlev Offenbach <detlev@die-offenbachs.de> |
10248 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing a proxy style to allow item selection by single/double click or | |
8 | platform default. | |
9 | """ | |
10 | ||
11 | from PyQt6.QtCore import Qt | |
12 | from PyQt6.QtWidgets import QApplication, QProxyStyle, QStyle | |
13 | ||
14 | ||
15 | class EricProxyStyle(QProxyStyle): | |
16 | """ | |
17 | Class implementing a proxy style to allow item selection by single/double click or | |
18 | platform default. | |
19 | """ | |
20 | ||
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
21 | def __init__(self, style=None, itemClickBehavior="default"): |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
22 | """ |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
23 | Constructor |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
24 | |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
25 | @param style style object or style name or None for the default native style |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
26 | (defaults to None) |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
27 | @type QStyle, str or None (optional) |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
28 | @param itemClickBehavior string describing the item activation behavior (one of |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
29 | "default", "doubleclick" or "singleclick") (defaults to "default") |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
30 | @type str (optional) |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
31 | """ |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
32 | super().__init__(style) |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
33 | |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
34 | self.__itemClickBehavior = itemClickBehavior |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
35 | |
10248 | 36 | def styleHint(self, hint, option=None, widget=None, returnData=None): |
37 | """ | |
38 | Public method returning a style hint for the given widget described by the | |
39 | provided style option. | |
40 | ||
41 | @param hint style hint to be determined | |
42 | @type QStyle.StyleHint | |
43 | @param option style option (defaults to None) | |
44 | @type QStyleOption (optional) | |
45 | @param widget reference to the widget (defaults to None) | |
46 | @type QWidget (optional) | |
47 | @param returnData data structure to return more data (defaults to None) | |
48 | @type QStyleHintReturn (optional) | |
49 | @return integer representing the style hint | |
50 | @rtype int | |
51 | """ | |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
52 | if ( |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
53 | hint == QStyle.StyleHint.SH_ItemView_ActivateItemOnSingleClick |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
54 | and QApplication.keyboardModifiers() == Qt.KeyboardModifier.NoModifier |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
55 | ): |
10248 | 56 | # Activate item with a single click? |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
57 | if self.__itemClickBehavior == "singleclick": |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
58 | return 1 |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
59 | elif self.__itemClickBehavior == "doubleclick": |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
60 | return 0 |
10248 | 61 | |
62 | # return the default style hint | |
63 | return super().styleHint( | |
64 | hint, option=option, widget=widget, returnData=returnData | |
65 | ) |