E5Gui/E5SideBar.py

branch
5_1_x
changeset 1448
b9c04bc0a692
parent 1441
0caac6d00bc2
child 1452
c45568ff630d
equal deleted inserted replaced
1445:b27f28bc5830 1448:b9c04bc0a692
6 """ 6 """
7 Module implementing a sidebar class. 7 Module implementing a sidebar class.
8 """ 8 """
9 9
10 from PyQt4.QtCore import QEvent, QSize, Qt, QByteArray, QDataStream, QIODevice 10 from PyQt4.QtCore import QEvent, QSize, Qt, QByteArray, QDataStream, QIODevice
11 from PyQt4.QtGui import QTabBar, QWidget, QStackedWidget, QBoxLayout, QToolButton 11 from PyQt4.QtGui import QTabBar, QWidget, QStackedWidget, QBoxLayout, QToolButton, QSizePolicy
12 12
13 from E5Gui.E5Application import e5App 13 from E5Gui.E5Application import e5App
14 14
15 import UI.PixmapCache 15 import UI.PixmapCache
16 16
36 QWidget.__init__(self, parent) 36 QWidget.__init__(self, parent)
37 37
38 self.__tabBar = QTabBar() 38 self.__tabBar = QTabBar()
39 self.__tabBar.setDrawBase(True) 39 self.__tabBar.setDrawBase(True)
40 self.__tabBar.setShape(QTabBar.RoundedNorth) 40 self.__tabBar.setShape(QTabBar.RoundedNorth)
41 self.__tabBar.setUsesScrollButtons(False) 41 self.__tabBar.setUsesScrollButtons(True)
42 self.__tabBar.setDrawBase(False)
42 self.__stackedWidget = QStackedWidget(self) 43 self.__stackedWidget = QStackedWidget(self)
43 self.__stackedWidget.setContentsMargins(0, 0, 0, 0) 44 self.__stackedWidget.setContentsMargins(0, 0, 0, 0)
44 self.__autoHideButton = QToolButton() 45 self.__autoHideButton = QToolButton()
45 self.__autoHideButton.setCheckable(True) 46 self.__autoHideButton.setCheckable(True)
46 self.__autoHideButton.setIcon(UI.PixmapCache.getIcon("autoHideOff.png")) 47 self.__autoHideButton.setIcon(UI.PixmapCache.getIcon("autoHideOff.png"))
199 (QIcon, string) 200 (QIcon, string)
200 @param label the labeltext of the tab (string) (only to be 201 @param label the labeltext of the tab (string) (only to be
201 used, if the second parameter is a QIcon) 202 used, if the second parameter is a QIcon)
202 """ 203 """
203 if label: 204 if label:
204 index = self.__tabBar.addTab(iconOrLabel, "") 205 self.__tabBar.addTab(iconOrLabel, label)
205 self.__tabBar.setTabToolTip(index, label)
206 else: 206 else:
207 self.__tabBar.addTab(iconOrLabel) 207 self.__tabBar.addTab(iconOrLabel)
208 self.__stackedWidget.addWidget(widget) 208 self.__stackedWidget.addWidget(widget)
209 if self.__orientation in [E5SideBar.North, E5SideBar.South]: 209 if self.__orientation in [E5SideBar.North, E5SideBar.South]:
210 self.__minSize = self.minimumSizeHint().height() 210 self.__minSize = self.minimumSizeHint().height()
221 (QIcon, string) 221 (QIcon, string)
222 @param label the labeltext of the tab (string) (only to be 222 @param label the labeltext of the tab (string) (only to be
223 used, if the second parameter is a QIcon) 223 used, if the second parameter is a QIcon)
224 """ 224 """
225 if label: 225 if label:
226 self.__tabBar.insertTab(index, iconOrLabel, "") 226 self.__tabBar.insertTab(index, iconOrLabel, label)
227 self.__tabBar.setTabToolTip(index, label)
228 else: 227 else:
229 self.__tabBar.insertTab(index, iconOrLabel) 228 self.__tabBar.insertTab(index, iconOrLabel)
230 self.__stackedWidget.insertWidget(index, widget) 229 self.__stackedWidget.insertWidget(index, widget)
231 if self.__orientation in [E5SideBar.North, E5SideBar.South]: 230 if self.__orientation in [E5SideBar.North, E5SideBar.South]:
232 self.__minSize = self.minimumSizeHint().height() 231 self.__minSize = self.minimumSizeHint().height()
361 Public method to set the orientation of the sidebar. 360 Public method to set the orientation of the sidebar.
362 @param orient orientation of the sidebar (North, East, South, West) 361 @param orient orientation of the sidebar (North, East, South, West)
363 """ 362 """
364 if orient == E5SideBar.North: 363 if orient == E5SideBar.North:
365 self.__tabBar.setShape(QTabBar.RoundedNorth) 364 self.__tabBar.setShape(QTabBar.RoundedNorth)
365 self.__tabBar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
366 self.barLayout.setDirection(QBoxLayout.LeftToRight) 366 self.barLayout.setDirection(QBoxLayout.LeftToRight)
367 self.layout.setDirection(QBoxLayout.TopToBottom) 367 self.layout.setDirection(QBoxLayout.TopToBottom)
368 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) 368 self.layout.setAlignment(self.barLayout, Qt.AlignLeft)
369 elif orient == E5SideBar.East: 369 elif orient == E5SideBar.East:
370 self.__tabBar.setShape(QTabBar.RoundedEast) 370 self.__tabBar.setShape(QTabBar.RoundedEast)
371 self.__tabBar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
371 self.barLayout.setDirection(QBoxLayout.TopToBottom) 372 self.barLayout.setDirection(QBoxLayout.TopToBottom)
372 self.layout.setDirection(QBoxLayout.RightToLeft) 373 self.layout.setDirection(QBoxLayout.RightToLeft)
373 self.layout.setAlignment(self.barLayout, Qt.AlignTop) 374 self.layout.setAlignment(self.barLayout, Qt.AlignTop)
374 elif orient == E5SideBar.South: 375 elif orient == E5SideBar.South:
375 self.__tabBar.setShape(QTabBar.RoundedSouth) 376 self.__tabBar.setShape(QTabBar.RoundedSouth)
377 self.__tabBar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
376 self.barLayout.setDirection(QBoxLayout.LeftToRight) 378 self.barLayout.setDirection(QBoxLayout.LeftToRight)
377 self.layout.setDirection(QBoxLayout.BottomToTop) 379 self.layout.setDirection(QBoxLayout.BottomToTop)
378 self.layout.setAlignment(self.barLayout, Qt.AlignLeft) 380 self.layout.setAlignment(self.barLayout, Qt.AlignLeft)
379 elif orient == E5SideBar.West: 381 elif orient == E5SideBar.West:
380 self.__tabBar.setShape(QTabBar.RoundedWest) 382 self.__tabBar.setShape(QTabBar.RoundedWest)
383 self.__tabBar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
381 self.barLayout.setDirection(QBoxLayout.TopToBottom) 384 self.barLayout.setDirection(QBoxLayout.TopToBottom)
382 self.layout.setDirection(QBoxLayout.LeftToRight) 385 self.layout.setDirection(QBoxLayout.LeftToRight)
383 self.layout.setAlignment(self.barLayout, Qt.AlignTop) 386 self.layout.setAlignment(self.barLayout, Qt.AlignTop)
384 self.__orientation = orient 387 self.__orientation = orient
385 388

eric ide

mercurial