Python源码示例:PyQt5.QtCore.Qt.AlignHCenter()
示例1
def on_list_success(self, job):
self.layout_workspaces.clear()
workspaces = job.ret
if not workspaces:
self.line_edit_search.hide()
label = QLabel(_("TEXT_WORKSPACE_NO_WORKSPACES"))
label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.layout_workspaces.addWidget(label)
return
self.line_edit_search.show()
for count, workspace in enumerate(workspaces):
workspace_fs, ws_entry, users_roles, files, timestamped = workspace
try:
self.add_workspace(
workspace_fs, ws_entry, users_roles, files, timestamped=timestamped
)
except JobSchedulerNotAvailable:
pass
示例2
def __init__(self, parent=None):
super().__init__(parent=parent)
self._border_radius = 10
self.label = QLabel('...', self)
self._size_grip = QSizeGrip(self)
self._size_grip.setFixedWidth(self._border_radius * 2)
font = self.font()
font.setPointSize(24)
self.label.setFont(font)
self.label.setAlignment(Qt.AlignBaseline | Qt.AlignVCenter | Qt.AlignHCenter)
self.label.setWordWrap(False)
self._layout = QHBoxLayout(self)
self._layout.setContentsMargins(0, 0, 0, 0)
self._layout.setSpacing(0)
self._layout.addSpacing(self._border_radius * 2)
self._layout.addWidget(self.label)
self._layout.addWidget(self._size_grip)
self._layout.setAlignment(self._size_grip, Qt.AlignBottom)
示例3
def data(self, index, role):
if index.isValid() or (0 <= index.row() < len(self.ListItemData)):
if role == Qt.DisplayRole:
return QVariant(self.ListItemData[index.row()]['name'])
elif role == Qt.DecorationRole:
return QVariant(QIcon(self.ListItemData[index.row()]['iconPath']))
elif role == Qt.SizeHintRole:
return QVariant(QSize(70,80))
elif role == Qt.TextAlignmentRole:
return QVariant(int(Qt.AlignHCenter|Qt.AlignVCenter))
elif role == Qt.FontRole:
font = QFont()
font.setPixelSize(20)
return QVariant(font)
else:
return QVariant()
示例4
def __init__(self, *args, **kwargs):
super(WidgetCode, self).__init__(*args, **kwargs)
self._sensitive = False # 是否大小写敏感
self.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.setBackgroundRole(QPalette.Midlight)
self.setAutoFillBackground(True)
# 字体
newFont = self.font()
newFont.setPointSize(16)
newFont.setFamily("Kristen ITC")
newFont.setBold(True)
self.setFont(newFont)
self.reset()
# 定时器
self.step = 0
self.timer = QBasicTimer()
self.timer.start(60, self)
示例5
def data(self, index, role):
"""Re-implemented method to get the data for a given index and role"""
node = index.internalPointer()
parent = node.parent
if parent:
if role == Qt.DisplayRole and index.column() == 5:
return node.name
elif not parent and role == Qt.DisplayRole and index.column() == 5:
return node.var_list()
elif not parent and role == Qt.DisplayRole:
if index.column() == 0:
return node.id
if index.column() == 1:
return node.name
if index.column() == 2:
return str(node.period)
if role == Qt.TextAlignmentRole and \
(index.column() == 4 or index.column() == 3):
return Qt.AlignHCenter | Qt.AlignVCenter
return None
示例6
def TabelaEntrega(self, tabela, row, col, data, cor, status):
item = QtWidgets.QLabel()
item.setAlignment(Qt.AlignLeading|Qt.AlignHCenter|
Qt.AlignVCenter)
item.setIndent(3)
item.setMargin(0)
item.setStyleSheet("background: #FFF")
html = ("""
<strong style="font-family:Arial; font-size: 13px;">{}<br/>
<span style="color:{}; font-size: 12px">{}</span></strong>"""
).format(data, cor, status)
item.setText(html)
tabela.setCellWidget(row, col, item)
# Texto Tabela Valor Produtos
示例7
def paintEvent(self, event):
painter = QPainter(self)
painter.setFont(self.font)
linear = QLinearGradient(QPoint(self.rect().topLeft()), QPoint(self.rect().bottomLeft()))
linear.setStart(0, 10)
linear.setFinalStop(0, 50)
linear.setColorAt(0.1, QColor(14, 179, 255));
linear.setColorAt(0.5, QColor(154, 232, 255));
linear.setColorAt(0.9, QColor(14, 179, 255));
linear2 = QLinearGradient(QPoint(self.rect().topLeft()), QPoint(self.rect().bottomLeft()))
linear2.setStart(0, 10)
linear2.setFinalStop(0, 50)
linear2.setColorAt(0.1, QColor(222, 54, 4));
linear2.setColorAt(0.5, QColor(255, 172, 116));
linear2.setColorAt(0.9, QColor(222, 54, 4));
painter.setPen(QColor(0, 0, 0, 200));
painter.drawText(QRect(1, 1, self.screen.width(), 60), Qt.AlignHCenter | Qt.AlignVCenter, self.lyric)
painter.setPen(QColor('transparent'));
self.textRect = painter.drawText(QRect(0, 0, self.screen.width(), 60), Qt.AlignHCenter | Qt.AlignVCenter, self.lyric)
painter.setPen(QPen(linear, 0))
painter.drawText(self.textRect, Qt.AlignLeft | Qt.AlignVCenter, self.lyric)
if self.intervel != 0:
self.widthBlock = self.textRect.width()/(self.intervel/150.0)
else:
self.widthBlock = 0
self.maskRect = QRectF(self.textRect.x(), self.textRect.y(), self.textRect.width(), self.textRect.height())
self.maskRect.setWidth(self.maskWidth)
painter.setPen(QPen(linear2, 0));
painter.drawText(self.maskRect, Qt.AlignLeft | Qt.AlignVCenter, self.lyric)
示例8
def __init__(self, experiment, **kwargs):
super().__init__(**kwargs)
self.experiment = experiment
self.container_layout = QVBoxLayout()
self.container_layout.setContentsMargins(0, 0, 0, 0)
StimDisplay = type("StimDisplay", (StimDisplayWidgetConditional, QWidget), {})
self.widget_display = StimDisplay(
self,
calibrator=self.experiment.calibrator,
protocol_runner=self.experiment.protocol_runner,
record_stim_framerate=None,
)
self.layout_inner = QVBoxLayout()
self.layout_inner.addWidget(self.widget_display)
self.button_show_display = QPushButton(
"Show stimulus (showing stimulus may impair performance)"
)
self.widget_display.display_state = False
self.button_show_display.clicked.connect(self.change_button)
self.layout_inner.addWidget(self.button_show_display)
self.layout_inner.setContentsMargins(12, 0, 12, 12)
self.container_layout.addLayout(self.layout_inner)
self.setLayout(self.container_layout)
self.container_layout.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.widget_display.sizeHint = lambda: QSize(100, 100)
sizePolicy = QSizePolicy(
QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding
)
self.widget_display.setSizePolicy(sizePolicy)
self.widget_display.setMaximumSize(500, 500)
示例9
def paint(self, painter, option, index):
option.displayAlignment = Qt.AlignHCenter | Qt.AlignVCenter
super().paint(painter, option, index)
示例10
def paint(self, painter, option, index):
option.displayAlignment = Qt.AlignHCenter | Qt.AlignVCenter
super().paint(painter, option, index)
示例11
def showSplashMessage(self, message: str) -> None:
"""Display text on the splash screen."""
if not QtApplication.splash:
self.createSplash()
if QtApplication.splash:
self.processEvents() # Process events from previous loading phase before updating the message
QtApplication.splash.showMessage(message, Qt.AlignHCenter | Qt.AlignVCenter) # Now update the message
self.processEvents() # And make sure it is immediately visible
elif self.getIsHeadLess():
Logger.log("d", message)
示例12
def initCategories(self):
generalButton = QListWidgetItem(self.categories)
generalButton.setIcon(QIcon(':/images/settings-general.png'))
generalButton.setText('General')
generalButton.setToolTip('General settings')
generalButton.setTextAlignment(Qt.AlignHCenter)
generalButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
videoButton = QListWidgetItem(self.categories)
videoButton.setIcon(QIcon(':/images/settings-video.png'))
videoButton.setText('Video')
videoButton.setToolTip('Video settings')
videoButton.setTextAlignment(Qt.AlignHCenter)
videoButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
themeButton = QListWidgetItem(self.categories)
themeButton.setIcon(QIcon(':/images/settings-theme.png'))
themeButton.setText('Theme')
themeButton.setToolTip('Theme settings')
themeButton.setTextAlignment(Qt.AlignHCenter)
themeButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ffmpegButton = QListWidgetItem(self.categories)
ffmpegButton.setIcon(QIcon(':/images/settings-ffmpeg.png'))
ffmpegButton.setText('Tools')
ffmpegButton.setToolTip('Tools settings')
ffmpegButton.setTextAlignment(Qt.AlignHCenter)
ffmpegButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
logsButton = QListWidgetItem(self.categories)
logsButton.setIcon(QIcon(':/images/settings-logs.png'))
logsButton.setText('Logs')
logsButton.setToolTip('Logging settings')
logsButton.setTextAlignment(Qt.AlignHCenter)
logsButton.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
self.categories.currentItemChanged.connect(self.changePage)
self.categories.setCurrentRow(0)
self.categories.setMaximumWidth(self.categories.sizeHintForColumn(0) + 2)
示例13
def __init__(self, defaultStr):
super().__init__(defaultStr)
self.setTextAlignment( Qt.AlignHCenter + Qt.AlignVCenter)
示例14
def paint(self, painter, option, index):
view_option = QStyleOptionViewItem(option)
view_option.decorationAlignment |= Qt.AlignHCenter
# Even though we told Qt that we don't want any selection on our
# list, it still adds a blue rectangle on focused items.
# So we just get rid of focus.
if option.state & QStyle.State_HasFocus:
view_option.state &= ~QStyle.State_HasFocus
super().paint(painter, view_option, index)
示例15
def on_list_error(self, job):
self.layout_workspaces.clear()
label = QLabel(_("TEXT_WORKSPACE_NO_WORKSPACES"))
label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.layout_workspaces.addWidget(label)
示例16
def paint(self, painter, option, index):
view_option = QStyleOptionViewItem(option)
view_option.decorationAlignment |= Qt.AlignHCenter
# Qt tries to be nice and adds a lovely background color
# on the focused item. Since we select items by rows and not
# individually, we don't want that, so we remove the focus
if option.state & QStyle.State_HasFocus:
view_option.state &= ~QStyle.State_HasFocus
if index.data(COPY_STATUS_DATA_INDEX):
view_option.font.setItalic(True)
super().paint(painter, view_option, index)
示例17
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
painter.setBrush(self.palette().color(QPalette.Window))
painter.drawRoundedRect(self.rect(), self._border_radius, self._border_radius)
painter.save()
painter.setPen(QColor('white'))
option = QTextOption()
option.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
rect = QRect(self.mapToParent(self._size_grip.pos()), self._size_grip.size())
painter.drawText(QRectF(rect), '●', option)
painter.restore()
示例18
def paintEvent(self, e):
painter = QPainter(self)
if self._size_grip.isVisible():
painter.save()
painter.setPen(QColor('white'))
option = QTextOption()
option.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
rect = QRect(self._size_grip.pos(), self._size_grip.size())
painter.drawText(QRectF(rect), '●', option)
painter.restore()
示例19
def __init__(self, picfile):
pixmap = QPixmap(picfile)
# , Qt.WindowStaysOnTopHint)
super(SplashScreen, self).__init__(pixmap)
# self.setMask(splash_pix.mask())
# self.raise_()
self.labelAlignment = int(Qt.AlignBottom | Qt.AlignHCenter | Qt.AlignAbsolute)
self.show()
QApplication.flush()
示例20
def paintEvent(self, event):
super(CoverLabel, self).paintEvent(event)
if hasattr(self, "cover_title") and self.cover_title != "":
# 底部绘制文字
painter = QPainter(self)
rect = self.rect()
# 粗略字体高度
painter.save()
fheight = self.fontMetrics().height()
# 底部矩形框背景渐变颜色
bottomRectColor = QLinearGradient(
rect.width() / 2, rect.height() - 24 - fheight,
rect.width() / 2, rect.height())
bottomRectColor.setSpread(QGradient.PadSpread)
bottomRectColor.setColorAt(0, QColor(255, 255, 255, 70))
bottomRectColor.setColorAt(1, QColor(0, 0, 0, 50))
# 画半透明渐变矩形框
painter.setPen(Qt.NoPen)
painter.setBrush(QBrush(bottomRectColor))
painter.drawRect(rect.x(), rect.height() - 24 -
fheight, rect.width(), 24 + fheight)
painter.restore()
# 距离底部一定高度画文字
font = self.font() or QFont()
font.setPointSize(8)
painter.setFont(font)
painter.setPen(Qt.white)
rect.setHeight(rect.height() - 12) # 底部减去一定高度
painter.drawText(rect, Qt.AlignHCenter |
Qt.AlignBottom, self.cover_title)
示例21
def paintEvent(self, event):
super(CoverLabel, self).paintEvent(event)
if hasattr(self, "cover_title") and self.cover_title != "":
# 底部绘制文字
painter = QPainter(self)
rect = self.rect()
# 粗略字体高度
painter.save()
fheight = self.fontMetrics().height()
# 底部矩形框背景渐变颜色
bottomRectColor = QLinearGradient(
rect.width() / 2, rect.height() - 24 - fheight,
rect.width() / 2, rect.height())
bottomRectColor.setSpread(QGradient.PadSpread)
bottomRectColor.setColorAt(0, QColor(255, 255, 255, 70))
bottomRectColor.setColorAt(1, QColor(0, 0, 0, 50))
# 画半透明渐变矩形框
painter.setPen(Qt.NoPen)
painter.setBrush(QBrush(bottomRectColor))
painter.drawRect(rect.x(), rect.height() - 24 -
fheight, rect.width(), 24 + fheight)
painter.restore()
# 距离底部一定高度画文字
font = self.font() or QFont()
font.setPointSize(8)
painter.setFont(font)
painter.setPen(Qt.white)
rect.setHeight(rect.height() - 12) # 底部减去一定高度
painter.drawText(rect, Qt.AlignHCenter |
Qt.AlignBottom, self.cover_title)
示例22
def __init__(self, *args, **kwargs):
super(LoadingWidget, self).__init__(*args, **kwargs)
self.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self._movie = QMovie("loading.gif")
self.setMovie(self._movie)
示例23
def createWindow():
app.w = QWidget()
# 模拟初始5秒后再显示
splash.showMessage('等待界面显示', Qt.AlignHCenter | Qt.AlignBottom, Qt.white)
QTimer.singleShot(3000, lambda: (
splash.showMessage('初始化完成', Qt.AlignHCenter | Qt.AlignBottom, Qt.white), app.w.show(),
splash.finish(app.w)))
# 模拟耗时5秒。但是不能用sleep
# 可以使用子线程加载耗时的数据
# 主线程中循环设置UI可以配合QApplication.instance().processEvents()
示例24
def __init__(self):
super().__init__()
text = QLabel()
text.setWordWrap(True)
button = QPushButton('Next quote >')
button.clicked.connect(lambda: text.setText(_get_quote()))
layout = QVBoxLayout()
layout.addWidget(text)
layout.addWidget(button)
layout.setAlignment(button, Qt.AlignHCenter)
self.setLayout(layout)
示例25
def conteudoTabela(self, tabela, row, col, data):
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(Qt.AlignJustify |
Qt.AlignHCenter | Qt.AlignVCenter)
item.setFlags(Qt.NoItemFlags)
item.setText(data)
tabela.setItem(row, col, item)
# Conteudo tabela alinhado a esquerda
示例26
def ValorProduto(self, tabela, row, col, valor):
item = QtWidgets.QLabel()
item.setAlignment(
Qt.AlignLeading|Qt.AlignHCenter|Qt.AlignVCenter)
item.setMargin(0)
item.setStyleSheet('background: #FFF')
html = ("""
<span style="font-family:'Arial'; font-size:30px;
font-weight: bold;"> <span style="font-size: 12px">R$</span> {}</span><br/>
""").format(valor)
item.setText(html)
tabela.setCellWidget(row, col, item)
# Status Operação coluna 1 tabela Compra/Venda
示例27
def TabelaQtdeStatus(self, tabela, row, col, qtde, cor):
item = QtWidgets.QLabel()
item.setAlignment(
Qt.AlignLeading|Qt.AlignHCenter|Qt.AlignVCenter)
item.setMargin(0)
item.setStyleSheet('background: #FFF')
html = ("""
<span style="font-family:'Arial'; font-size:30px;
font-weight: bold;color:{} ">{}</span><br/>
""").format(cor, qtde)
item.setText(html)
tabela.setCellWidget(row, col, item)
# Texto ID tabelas
示例28
def TabelaID(self, tabela, row, col, id):
item = QtWidgets.QLabel()
item.setAlignment(
Qt.AlignLeading|Qt.AlignHCenter|Qt.AlignVCenter)
item.setMargin(0)
item.setStyleSheet('background: #FFF;')
html = ("""
<span style="font-family:'Arial'; font-size:30px;
font-weight: bold;color:#7AB32E ">{}</span><br/>
""").format(id)
item.setText(html)
tabela.setCellWidget(row, col, item)
#Botao Receber/ Pagar Parcela
示例29
def qflags_key(base: typing.Type,
value: typing.Union[int, sip.simplewrapper],
add_base: bool = False,
klass: typing.Type = None) -> str:
"""Convert a Qt QFlags value to its keys as string.
Note: Passing a combined value (such as Qt.AlignCenter) will get the names
for the individual bits (e.g. Qt.AlignVCenter | Qt.AlignHCenter). FIXME
https://github.com/qutebrowser/qutebrowser/issues/42
Args:
base: The object the flags are in, e.g. QtCore.Qt
value: The value to get.
add_base: Whether the base should be added to the printed names.
klass: The flags class the value belongs to.
If None, the class will be auto-guessed.
Return:
The keys associated with the flags as a '|' separated string if they
could be found. Hex values as a string if not.
"""
if klass is None:
# We have to store klass here because it will be lost when iterating
# over the bits.
klass = value.__class__
if klass == int:
raise TypeError("Can't guess enum class of an int!")
if not value:
return qenum_key(base, value, add_base, klass)
bits = []
names = []
mask = 0x01
value = int(value) # type: ignore[arg-type]
while mask <= value:
if value & mask:
bits.append(mask)
mask <<= 1
for bit in bits:
# We have to re-convert to an enum type here or we'll sometimes get an
# empty string back.
enum_value = klass(bit) # type: ignore[call-arg]
names.append(qenum_key(base, enum_value, add_base))
return '|'.join(names)
示例30
def __init__(self, pipe, app_mode=False, **kwargs):
super().__init__(**kwargs)
self.setLayout(QGridLayout())
self.layout().setAlignment(Qt.AlignTop)
self._app_mode = app_mode
# Input selection
self.inputBox = QComboBox(self)
self.layout().addWidget(self.inputBox, 0, 0, 1, 3)
self.__init_inputs()
# Current plugins list
self.currentList = QListWidget(self)
self.currentList.setDragEnabled(True)
self.currentList.setDragDropMode(QAbstractItemView.InternalMove)
self.layout().addWidget(self.currentList, 1, 0)
# Available plugins list
self.availableList = QListWidget(self)
self.layout().addWidget(self.availableList, 1, 2)
# Output selection
self.outputBox = QComboBox(self)
self.layout().addWidget(self.outputBox, 4, 0, 1, 3)
self.__init_outputs()
# Add/Remove plugins buttons
self.buttonsLayout = QVBoxLayout()
self.layout().addLayout(self.buttonsLayout, 1, 1)
self.layout().setAlignment(self.buttonsLayout, Qt.AlignHCenter)
self.addButton = QPushButton(self)
self.addButton.setIcon(QIcon.fromTheme('go-previous'))
self.addButton.clicked.connect(self.__add_plugin)
self.buttonsLayout.addWidget(self.addButton)
self.buttonsLayout.setAlignment(self.addButton, Qt.AlignHCenter)
self.delButton = QPushButton(self)
self.delButton.setIcon(QIcon.fromTheme('go-next'))
self.delButton.clicked.connect(self.__remove_plugin)
self.buttonsLayout.addWidget(self.delButton)
self.buttonsLayout.setAlignment(self.delButton, Qt.AlignHCenter)
# Load the pipeline
self.set_pipe(pipe)