test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Header.py
Go to the documentation of this file.
1 from PyQt4.QtCore import Qt,SIGNAL
2 from PyQt4.QtGui import QHeaderView, QStandardItemModel, QToolButton, QFrame, QVBoxLayout, QSizePolicy
3 
4 
5 class FrameWithHeader(QFrame):
6 
7  def __init__(self, parent=None):
8  QFrame.__init__(self, parent)
9  self.setFrameShadow(QFrame.Raised)
10  self.setFrameStyle(QFrame.StyledPanel)
11  self.setLayout(QVBoxLayout())
12  self.layout().setContentsMargins(0, 0, 0, 0)
13  self.layout().setSpacing(0)
14 
15  self._header = Header(Qt.Horizontal, self)
16  self.layout().addWidget(self._header)
17 
18  def addWidget(self, widget):
19  if isinstance(widget, QFrame):
20  widget.setFrameStyle(QFrame.NoFrame)
21  self.layout().addWidget(widget)
22 
23  def header(self):
24  return self._header
25 
26 class Header(QHeaderView):
27 
28  def __init__(self, orientation, parent=None):
29  QHeaderView.__init__(self, orientation, parent)
30 
31  self.setModel(QStandardItemModel(self))
32  self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
33  self.setStretchLastSection(True)
34  self.setFixedHeight(25)
35  self._menuButton = None
36 
37  def createMenuButton(self, label=">"):
38  self._menuButton = QToolButton(self)
39  self._menuButton.setText(label)
40  return self._menuButton
41 
42  def menuButton(self):
43  return self._menuButton
44 
45  def setText(self, text):
46  if self.orientation() == Qt.Horizontal:
47  self.model().setHorizontalHeaderLabels([text])
48  elif self.orientation() == Qt.Vertical:
49  self.model().setVerticalHeaderLabels([text])
50 
51  def mousePressEvent(self,event):
52  QHeaderView.mousePressEvent(self,event)
53  if event.button()==Qt.RightButton:
54  self.emit(SIGNAL("mouseRightPressed"), event.globalPos())