1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a horizontal and a vertical toolbox class. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtWidgets import QToolBox, QTabWidget |
|
11 |
|
12 from .E5TabWidget import E5TabWidget |
|
13 |
|
14 |
|
15 class E5VerticalToolBox(QToolBox): |
|
16 """ |
|
17 Class implementing a ToolBox class substituting QToolBox to support wheel |
|
18 events. |
|
19 """ |
|
20 def __init__(self, parent=None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param parent reference to the parent widget (QWidget) |
|
25 """ |
|
26 super().__init__(parent) |
|
27 |
|
28 |
|
29 class E5HorizontalToolBox(E5TabWidget): |
|
30 """ |
|
31 Class implementing a vertical QToolBox like widget. |
|
32 """ |
|
33 def __init__(self, parent=None): |
|
34 """ |
|
35 Constructor |
|
36 |
|
37 @param parent reference to the parent widget (QWidget) |
|
38 """ |
|
39 E5TabWidget.__init__(self, parent) |
|
40 self.setTabPosition(QTabWidget.TabPosition.West) |
|
41 self.setUsesScrollButtons(True) |
|
42 |
|
43 def addItem(self, widget, icon, text): |
|
44 """ |
|
45 Public method to add a widget to the toolbox. |
|
46 |
|
47 @param widget reference to the widget to be added (QWidget) |
|
48 @param icon the icon to be shown (QIcon) |
|
49 @param text the text to be shown (string) |
|
50 @return index of the added widget (integer) |
|
51 """ |
|
52 index = self.addTab(widget, icon, "") |
|
53 self.setTabToolTip(index, text) |
|
54 return index |
|
55 |
|
56 def insertItem(self, index, widget, icon, text): |
|
57 """ |
|
58 Public method to add a widget to the toolbox. |
|
59 |
|
60 @param index position at which the widget should be inserted (integer) |
|
61 @param widget reference to the widget to be added (QWidget) |
|
62 @param icon the icon to be shown (QIcon) |
|
63 @param text the text to be shown (string) |
|
64 @return index of the added widget (integer) |
|
65 """ |
|
66 index = self.insertTab(index, widget, icon, "") |
|
67 self.setTabToolTip(index, text) |
|
68 return index |
|
69 |
|
70 def removeItem(self, index): |
|
71 """ |
|
72 Public method to remove a widget from the toolbox. |
|
73 |
|
74 @param index index of the widget to remove (integer) |
|
75 """ |
|
76 self.removeTab(index) |
|
77 |
|
78 def setItemToolTip(self, index, toolTip): |
|
79 """ |
|
80 Public method to set the tooltip of an item. |
|
81 |
|
82 @param index index of the item (integer) |
|
83 @param toolTip tooltip text to be set (string) |
|
84 """ |
|
85 self.setTabToolTip(index, toolTip) |
|
86 |
|
87 def setItemEnabled(self, index, enabled): |
|
88 """ |
|
89 Public method to set the enabled state of an item. |
|
90 |
|
91 @param index index of the item (integer) |
|
92 @param enabled flag indicating the enabled state (boolean) |
|
93 """ |
|
94 self.setTabEnabled(index, enabled) |
|