Python源码示例:PyQt5.QtCore.Qt.Vertical()
示例1
def set_inspector(self, inspector_widget: inspector.AbstractWebInspector,
position: inspector.Position) -> None:
"""Set the position of the inspector."""
assert position != inspector.Position.window
if position in [inspector.Position.right, inspector.Position.bottom]:
self._main_idx = 0
self._inspector_idx = 1
else:
self._inspector_idx = 0
self._main_idx = 1
self.setOrientation(Qt.Horizontal
if position in [inspector.Position.left,
inspector.Position.right]
else Qt.Vertical)
self.insertWidget(self._inspector_idx, inspector_widget)
self._position = position
self._load_preferred_size()
self._adjust_size()
示例2
def buttonsLayout(self):
self.matrix = False
vbox = QVBoxLayout()
interactionModeLayout = QVBoxLayout()
self.interactionModeButton = QtWidgets.QPushButton('visma')
self.interactionModeButton.clicked.connect(self.interactionMode)
interactionModeLayout.addWidget(self.interactionModeButton)
interactionModeWidget = QWidget(self)
interactionModeWidget.setLayout(interactionModeLayout)
interactionModeWidget.setFixedSize(275, 50)
topButtonSplitter = QSplitter(Qt.Horizontal)
topButtonSplitter.addWidget(interactionModeWidget)
permanentButtons = QWidget(self)
topButtonSplitter.addWidget(permanentButtons)
self.bottomButton = QFrame()
self.buttonSplitter = QSplitter(Qt.Vertical)
self.buttonSplitter.addWidget(topButtonSplitter)
self.buttonSplitter.addWidget(self.bottomButton)
vbox.addWidget(self.buttonSplitter)
return vbox
示例3
def mousePressEvent(self, e):
cr = self._control_rect()
if e.button() == Qt.LeftButton and not cr.contains(e.pos()):
# Set the value to the minimum
value = self.minimum()
# zmax is the maximum value starting from zero
zmax = self.maximum() - self.minimum()
if self.orientation() == Qt.Vertical:
# Add the current position multiplied for value/size ratio
value += (self.height() - e.y()) * (zmax / self.height())
else:
value += e.x() * (zmax / self.width())
if self.value() != value:
self.setValue(value)
self.sliderJumped.emit(self.value())
e.accept()
else:
e.ignore()
else:
super().mousePressEvent(e)
示例4
def doLayout(self, rect, testOnly):
x = rect.x()
y = rect.y()
lineHeight = 0
for item in self.itemList:
wid = item.widget()
spaceX = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton,
Qt.Horizontal)
spaceY = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton,
Qt.Vertical)
nextX = x + item.sizeHint().width() + spaceX
if nextX - spaceX > rect.right() and lineHeight > 0:
x = rect.x()
y = y + lineHeight + spaceY
nextX = x + item.sizeHint().width() + spaceX
lineHeight = 0
if not testOnly:
item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
x = nextX
lineHeight = max(lineHeight, item.sizeHint().height())
return y + lineHeight - rect.y()
示例5
def doLayout(self, rect, testOnly):
x = rect.x()
y = rect.y()
lineHeight = 0
for item in self.itemList:
wid = item.widget()
spaceX = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton,
QSizePolicy.PushButton, Qt.Horizontal)
spaceY = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton,
QSizePolicy.PushButton, Qt.Vertical)
nextX = x + item.sizeHint().width() + spaceX
if nextX - spaceX > rect.right() and lineHeight > 0:
x = rect.x()
y = y + lineHeight + spaceY
nextX = x + item.sizeHint().width() + spaceX
lineHeight = 0
if not testOnly:
item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
x = nextX
lineHeight = max(lineHeight, item.sizeHint().height())
return y + lineHeight - rect.y()
示例6
def __init__(self, *args, **kwargs):
super(DemoWindow, self).__init__(*args, **kwargs)
self.resize(600, 600)
layout = QFormLayout(self)
self.label1 = QLabel('0', self)
layout.addRow(self.label1, ClickJumpSlider(
Qt.Horizontal, valueChanged=lambda v: self.label1.setText(str(v))))
# 横向-反向显示
self.label2 = QLabel('0', self)
layout.addRow(self.label2, ClickJumpSlider(
Qt.Horizontal, invertedAppearance=True,
valueChanged=lambda v: self.label2.setText(str(v))))
self.label3 = QLabel('0', self)
layout.addRow(self.label3, ClickJumpSlider(
Qt.Vertical, minimumHeight=200, valueChanged=lambda v: self.label3.setText(str(v))))
# 纵向反向显示
self.label4 = QLabel('0', self)
layout.addRow(self.label4, ClickJumpSlider(
Qt.Vertical, invertedAppearance=True,
minimumHeight=200, valueChanged=lambda v: self.label4.setText(str(v))))
示例7
def data(self, index, role=None):
row = index.row()
col = index.column()
if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.ToolTipRole:
if self.orientation == Qt.Horizontal:
if type(self.df.columns) == pd.MultiIndex:
return str(self.df.columns.values[col][row])
else:
return str(self.df.columns.values[col])
elif self.orientation == Qt.Vertical:
if type(self.df.index) == pd.MultiIndex:
return str(self.df.index.values[row][col])
else:
return str(self.df.index.values[row])
# The headers of this table will show the level names of the MultiIndex
示例8
def sizeHint(self):
# Horizontal HeaderView
if self.orientation == Qt.Horizontal:
# Width of DataTableView
width = self.table.sizeHint().width() + self.verticalHeader().width()
# Height
height = 2 * self.frameWidth() # Account for border & padding
for i in range(self.model().rowCount()):
height += self.rowHeight(i)
# Vertical HeaderView
else:
# Height of DataTableView
height = self.table.sizeHint().height() + self.horizontalHeader().height()
# Width
width = 2 * self.frameWidth() # Account for border & padding
for i in range(self.model().columnCount()):
width += self.columnWidth(i)
return QSize(width, height)
# This is needed because otherwise when the horizontal header is a single row it will add whitespace to be bigger
示例9
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.m = m = PlotCanvas(self, width=5, height=4)
m.move(0,0)
sld = QSlider(Qt.Vertical, self)
sld.setFocusPolicy(Qt.NoFocus)
sld.setGeometry(500, 40, 100, 90)
sld.valueChanged[int].connect(self.changeValue)
# button.setToolTip('This s an example button')
# button.move(500,0)
# button.resize(140,100)
self.show()
示例10
def paintEvent(self, e):
"""Extend paintEvent to emit a signal if the scroll position changed.
This is a bit of a hack: We listen to repaint requests here, in the
hope a repaint will always be requested when scrolling, and if the
scroll position actually changed, we emit a signal.
QtWebEngine has a scrollPositionChanged signal, so it's not needed
there.
Args:
e: The QPaintEvent.
Return:
The superclass event return value.
"""
frame = self.page().mainFrame()
new_pos = (frame.scrollBarValue(Qt.Horizontal),
frame.scrollBarValue(Qt.Vertical))
if self._old_scroll_pos != new_pos:
self._old_scroll_pos = new_pos
m = (frame.scrollBarMaximum(Qt.Horizontal),
frame.scrollBarMaximum(Qt.Vertical))
perc = (round(100 * new_pos[0] / m[0]) if m[0] != 0 else 0,
round(100 * new_pos[1] / m[1]) if m[1] != 0 else 0)
self.scroll_pos = perc
self.scroll_pos_changed.emit(*perc)
# Let superclass handle the event
super().paintEvent(e)
示例11
def to_perc(self, x=None, y=None):
if x is None and y == 0:
self.top()
elif x is None and y == 100:
self.bottom()
else:
for val, orientation in [(x, Qt.Horizontal), (y, Qt.Vertical)]:
if val is not None:
frame = self._widget.page().mainFrame()
maximum = frame.scrollBarMaximum(orientation)
if maximum == 0:
continue
pos = int(maximum * val / 100)
pos = qtutils.check_overflow(pos, 'int', fatal=False)
frame.setScrollBarValue(orientation, pos)
示例12
def up(self, count=1):
self._key_press(Qt.Key_Up, count, 'scrollBarMinimum', Qt.Vertical)
示例13
def down(self, count=1):
self._key_press(Qt.Key_Down, count, 'scrollBarMaximum', Qt.Vertical)
示例14
def page_up(self, count=1):
self._key_press(Qt.Key_PageUp, count, 'scrollBarMinimum', Qt.Vertical)
示例15
def at_bottom(self):
frame = self._widget.page().currentFrame()
return self.pos_px().y() >= frame.scrollBarMaximum(Qt.Vertical)
示例16
def headerData(self, section, orientation, role = Qt.DisplayRole):
if role != Qt.DisplayRole:
return None
if ((orientation == Qt.Horizontal) and self.isRowObjects) or ((orientation == Qt.Vertical) and not self.isRowObjects):
# Display property headers.
try:
return self.properties[section]['header'] # Property header.
except (IndexError, KeyError):
return None
else:
# Display object indices (1-based).
return (section + 1) if (0 <= section < len(self.objects)) else None
示例17
def headerData(self, column, orientation, role=Qt.DisplayRole):
if role == Qt.DisplayRole and orientation == Qt.Vertical:
idx = self.index(column, 0)
if idx.isValid():
idx = self.mapFromSource(idx)
return str(idx.row() + 1)
else:
return ExtSortFilterTableModel.headerData(self, column, orientation, role)
示例18
def restore_splitter_sizes(window: QDialog, splitter: QSplitter):
global cache
if cache:
symbol = window.__class__.__name__ + '_' + splitter.objectName()
sizes = cache.get_value(symbol, None, list)
if not isinstance(sizes, list) or len(sizes) != 2:
sizes = [100, 100]
if splitter.parent():
if splitter.orientation() == Qt.Vertical:
sizes[0], sizes[1] = round(splitter.parent().height() / 2), round(splitter.parent().height() / 2)
else:
sizes[0], sizes[1] = round(splitter.parent().width() / 2), round(splitter.parent().width() / 2)
splitter.setSizes(sizes)
示例19
def prepareLayout(self):
self._splitter = splitter((self.tree,self.properties_editor),
stretch_factors = (2,1),
orientation=Qt.Vertical)
layout(self,(self._splitter,),top_widget=self)
self._splitter.show()
示例20
def headerData(self, section, orientation, role=Qt.DisplayRole):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
if section < len(self.columns):
return self.columns[section]
else:
return section + 1
if role == Qt.SizeHintRole and orientation == Qt.Vertical:
return 0
示例21
def initUI(self):
# self.setGeometry(10, 10, 800, 600)
self.resize(self.mainWidth, self.mainHeight)
self.center()
self.setWindowTitle('Sparrow-WiFi Analyzer')
self.setWindowIcon(QIcon('wifi_icon.png'))
self.createMenu()
self.createControls()
#self.splitter1 = QSplitter(Qt.Vertical)
#self.splitter2 = QSplitter(Qt.Horizontal)
#self.splitter1.addWidget(self.networkTable)
#self.splitter1.addWidget(self.splitter2)
#self.splitter2.addWidget(self.Plot24)
#self.splitter2.addWidget(self.Plot5)
self.setBlackoutColors()
self.setMinimumWidth(800)
self.setMinimumHeight(400)
self.show()
# Set up GPS check timer
self.gpsTimer = QTimer()
self.gpsTimer.timeout.connect(self.onGPSTimer)
self.gpsTimer.setSingleShot(True)
self.gpsTimerTimeout = 5000
self.gpsTimer.start(self.gpsTimerTimeout) # Check every 5 seconds
示例22
def _do_layout(self, rect, test_only):
x = rect.x()
y = rect.y()
line_height = 0
for item in self.items:
w = item.widget()
space_x = self.horizontalSpacing()
if space_x == -1:
space_x = w.style().layoutSpacing(
QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Horizontal
)
space_y = self.verticalSpacing()
if space_y == -1:
space_y = w.style().layoutSpacing(
QSizePolicy.QPushButton, QSizePolicy.QPushButton, Qt.Vertical
)
next_x = x + item.sizeHint().width() + space_x
if next_x - space_x > rect.right() and line_height > 0:
x = rect.x()
y = y + line_height + space_y
next_x = x + item.sizeHint().width() + space_x
line_height = 0
if not test_only:
item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
x = next_x
line_height = max(line_height, item.sizeHint().height())
return y + line_height - rect.x()
示例23
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.setAttribute(Qt.WA_StyledBackground, True)
self.setStyleSheet('Window{background:gray;}')
layout = QVBoxLayout(self)
self.labelValue = QLabel(self)
layout.addWidget(CSlider(
Qt.Vertical, self, valueChanged=lambda v: self.labelValue.setText(str(v))))
layout.addWidget(CSlider(
Qt.Horizontal, self, valueChanged=lambda v: self.labelValue.setText(str(v))))
layout.addWidget(self.labelValue)
示例24
def initUI(self):
hbox = QHBoxLayout(self)
topleft = QFrame(self)
topleft.setFrameShape(QFrame.StyledPanel)
topright = QFrame(self)
topright.setFrameShape(QFrame.StyledPanel)
bottom = QFrame(self)
bottom.setFrameShape(QFrame.StyledPanel)
splitter1 = QSplitter(Qt.Horizontal)
splitter1.addWidget(topleft) # 添加左上角窗口
splitter1.addWidget(topright) # 添加右上角窗口
splitter2 = QSplitter(Qt.Vertical)
splitter2.addWidget(splitter1) # 添加splitter1,里面嵌套了上面的内容
splitter2.addWidget(bottom) # 添加底部窗口
hbox.addWidget(splitter2)
self.setLayout(hbox)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QSplitter')
self.show()
示例25
def headerData(self, section, orientation, role):
if role == Qt.DisplayRole:
if orientation == Qt.Horizontal:
return self.colHeaders[section]
elif orientation == Qt.Vertical:
if self.get_row_headers is not None:
self.rowHeaders = self.get_row_headers()
if len(self.rowHeaders) == 0:
return None
return self.rowHeaders[section]
else:
return None
示例26
def headerData(self, sekcja, kierunek, rola=Qt.DisplayRole):
""" Zwraca nagłówki kolumn """
if rola == Qt.DisplayRole and kierunek == Qt.Horizontal:
return self.pola[sekcja]
elif rola == Qt.DisplayRole and kierunek == Qt.Vertical:
return sekcja + 1
else:
return QVariant()
示例27
def headerData(self, sekcja, kierunek, rola=Qt.DisplayRole):
""" Zwraca nagłówki kolumn """
if rola == Qt.DisplayRole and kierunek == Qt.Horizontal:
return self.pola[sekcja]
elif rola == Qt.DisplayRole and kierunek == Qt.Vertical:
return sekcja + 1
else:
return QVariant()
示例28
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.setAttribute(Qt.WA_StyledBackground, True)
layout = QVBoxLayout(self)
layout.addWidget(QSlider(Qt.Vertical, self))
layout.addWidget(QSlider(Qt.Horizontal, self))
示例29
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.setAttribute(Qt.WA_StyledBackground, True)
layout = QVBoxLayout(self)
layout.addWidget(PaintQSlider(Qt.Vertical, self, minimumWidth=90))
layout.addWidget(PaintQSlider(Qt.Horizontal, self, minimumHeight=90))
示例30
def setOrientation(self, checked):
hor = self.sender() == self.radioButtonHor
if checked:
self.stackedWidget.setOrientation(
Qt.Horizontal if hor else Qt.Vertical)