src/eric7/EricWidgets/EricProxyStyle.py

branch
eric7
changeset 10933
95a15b70f7bb
parent 10439
21c28b0f9e41
child 11090
f5f5f5803935
equal deleted inserted replaced
10932:82de5109035a 10933:95a15b70f7bb
9 """ 9 """
10 10
11 from PyQt6.QtCore import Qt 11 from PyQt6.QtCore import Qt
12 from PyQt6.QtWidgets import QApplication, QProxyStyle, QStyle 12 from PyQt6.QtWidgets import QApplication, QProxyStyle, QStyle
13 13
14 from eric7 import Preferences
15
16 14
17 class EricProxyStyle(QProxyStyle): 15 class EricProxyStyle(QProxyStyle):
18 """ 16 """
19 Class implementing a proxy style to allow item selection by single/double click or 17 Class implementing a proxy style to allow item selection by single/double click or
20 platform default. 18 platform default.
21 """ 19 """
20
21 def __init__(self, style=None, itemClickBehavior="default"):
22 """
23 Constructor
24
25 @param style style object or style name or None for the default native style
26 (defaults to None)
27 @type QStyle, str or None (optional)
28 @param itemClickBehavior string describing the item activation behavior (one of
29 "default", "doubleclick" or "singleclick") (defaults to "default")
30 @type str (optional)
31 """
32 super().__init__(style)
33
34 self.__itemClickBehavior = itemClickBehavior
22 35
23 def styleHint(self, hint, option=None, widget=None, returnData=None): 36 def styleHint(self, hint, option=None, widget=None, returnData=None):
24 """ 37 """
25 Public method returning a style hint for the given widget described by the 38 Public method returning a style hint for the given widget described by the
26 provided style option. 39 provided style option.
34 @param returnData data structure to return more data (defaults to None) 47 @param returnData data structure to return more data (defaults to None)
35 @type QStyleHintReturn (optional) 48 @type QStyleHintReturn (optional)
36 @return integer representing the style hint 49 @return integer representing the style hint
37 @rtype int 50 @rtype int
38 """ 51 """
39 if hint == QStyle.StyleHint.SH_ItemView_ActivateItemOnSingleClick: 52 if (
53 hint == QStyle.StyleHint.SH_ItemView_ActivateItemOnSingleClick
54 and QApplication.keyboardModifiers() == Qt.KeyboardModifier.NoModifier
55 ):
40 # Activate item with a single click? 56 # Activate item with a single click?
41 activate = Preferences.getUI("ActivateItemOnSingleClick") 57 if self.__itemClickBehavior == "singleclick":
42 if QApplication.keyboardModifiers() == Qt.KeyboardModifier.NoModifier: 58 return 1
43 if activate == "singleclick": 59 elif self.__itemClickBehavior == "doubleclick":
44 return 1 60 return 0
45 elif activate == "doubleclick":
46 return 0
47 61
48 # return the default style hint 62 # return the default style hint
49 return super().styleHint( 63 return super().styleHint(
50 hint, option=option, widget=widget, returnData=returnData 64 hint, option=option, widget=widget, returnData=returnData
51 ) 65 )

eric ide

mercurial