我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用PyQt5.QtCore.Qt.AlignBottom()。
def init_widget(self): self.setWindowTitle("Layout Basic") self.setFixedWidth(640) self.setFixedHeight(480) self.lb_1.setText("Label 1") self.lb_2.setText("Label 2") self.lb_3.setText("Label 3") self.lb_4.setText("Label 4") self.lb_5.setText("Label 5") self.lb_1.setStyleSheet("background-color: yellow") self.lb_2.setStyleSheet("background-color: red") self.lb_3.setStyleSheet("background-color: blue") self.lb_4.setStyleSheet("background-color: pink") self.lb_5.setStyleSheet("background-color: grey") self.layout_1.addWidget(self.lb_1) self.layout_1.addWidget(self.lb_2, alignment=Qt.AlignTop) self.layout_1.addWidget(self.lb_3, alignment=Qt.AlignBottom) self.layout_1.addWidget(self.lb_4, alignment=Qt.AlignVCenter) self.layout_1.addWidget(self.lb_5, alignment=Qt.AlignHCenter)
def init_top_layout(self): history = FIRST.server.history(self.metadata_id) if (not history or ('results' not in history) or (self.metadata_id not in history['results']) or ('creator' not in history['results'][self.metadata_id]) or ('history' not in history['results'][self.metadata_id])): self.should_show = False return self.creator = history['results'][self.metadata_id]['creator'] self.history = history['results'][self.metadata_id]['history'] title = QtWidgets.QLabel('Revision History') title.setStyleSheet('font: 16pt;') creator = QtWidgets.QLabel('by: <b>{}</b>'.format(self.creator)) creator.setAlignment(Qt.AlignRight | Qt.AlignBottom) self.top_layout.addWidget(title) self.top_layout.addStretch() self.top_layout.addWidget(creator)
def req_ui(self): self.clear_layout(self.rbox) self.clear_layout(self.hbox) self.hbox.addStretch() self.l1.setText('Select which requirements to install') self.rbox.insertSpacing(1, 35) self.r1 = QRadioButton("Install basic + audio requirements (recommended)") self.r1.setChecked(True) self.r1.setFont(self.reg_font) self.rbox.addWidget(self.r1, 0, Qt.AlignTop) self.r2 = QRadioButton("Install basic requirements") self.r2.setFont(self.reg_font) self.rbox.addWidget(self.r2, 0, Qt.AlignLeft) if os.path.exists("lib"): l5 = QLabel(self) l5.setText('<font color="#ff0000">Requirements already installed.</font>') self.rbox.addWidget(l5, 1, Qt.AlignBottom) b5 = QPushButton("Skip", self) b5.setMaximumWidth(50) self.rbox.addWidget(b5, 0, Qt.AlignBottom) b5.clicked.connect(self.token_ui) # buttons self.buttons_panel() # binds self.b1.setEnabled(False) self.b2.clicked.connect(self.if_req) self.b3.clicked.connect(self.close_prompt)
def drawCellHeaderText(self, painter, rect): xMin, yMin, width, height = rect metrics = QFontMetrics(headerFont) minOffset = painter.pen().width() painter.setFont(headerFont) painter.setPen(cellMetricsTextColor) name = metrics.elidedText( self.glyph.name, Qt.ElideRight, width - 2) painter.drawText( 1, 0, width - 2, height - minOffset, Qt.TextSingleLine | Qt.AlignCenter | Qt.AlignBottom, name)
def createLabel(self, text): lbl = QLabel(text) lbl.setAlignment(Qt.AlignHCenter | Qt.AlignBottom) return lbl
def data(self, index: QModelIndex, role=Qt.DisplayRole): if not index.isValid(): return None i = index.row() j = index.column() if role == Qt.DisplayRole and self.display_data: try: if self.proto_view == 0: return self.display_data[i][j] elif self.proto_view == 1: return "{0:x}".format(self.display_data[i][j]) elif self.proto_view == 2: return chr(self.display_data[i][j]) except IndexError: return None elif role == Qt.TextAlignmentRole: if i in self.first_messages: return Qt.AlignHCenter + Qt.AlignBottom else: return Qt.AlignCenter elif role == Qt.BackgroundColorRole: return self.background_colors[i, j] elif role == Qt.FontRole: font = QFont() font.setBold(self.bold_fonts[i, j]) font.setItalic(self.italic_fonts[i, j]) return font elif role == Qt.TextColorRole: return self.text_colors[i, j] elif role == Qt.ToolTipRole: return self.get_tooltip(i, j) else: return None
def init_top_layout(self): title = QtWidgets.QLabel('Mass Function Upload') title.setStyleSheet('font: 16pt;') description = QtWidgets.QLabel(( 'Upload function prototype to server for others to access.\n' 'Select the functions you want to upload. Click to select a ' 'function and click again to deselect the function. Once ' 'uploaded you can manage prototypes you\'ve created in the ' 'management window.')) description.setWordWrap(True) description.setLineWidth(200) description.setStyleSheet('text-size: 90%') vbox_text = QtWidgets.QVBoxLayout() vbox_text.addWidget(title) vbox_text.addWidget(description) vbox_legend = QtWidgets.QVBoxLayout() grid_legend = QtWidgets.QGridLayout() style = 'background-color: #{0:06x}; border: 1px solid #c0c0c0;' colors = [ FIRST.color_changed, FIRST.color_unchanged, FIRST.color_default, FIRST.color_selected] text = ['Changed', 'Unchanged', 'Default', 'Selected'] for i in xrange(len(colors)): box = QtWidgets.QLabel() box.setFixedHeight(10) box.setFixedWidth(10) box.setStyleSheet(style.format(colors[i].color().rgb() & 0xFFFFFF)) grid_legend.addWidget(box, i, 0) grid_legend.addWidget(QtWidgets.QLabel(text[i]), i, 1) vbox_legend.addLayout(grid_legend) vbox_legend.setAlignment(Qt.AlignRight | Qt.AlignBottom) self.top_layout.addLayout(vbox_text) self.top_layout.addStretch() self.top_layout.addLayout(vbox_legend)
def init_top_layout(self): title = QtWidgets.QLabel('Check All Functions') title.setStyleSheet('font: 16pt;') description = QtWidgets.QLabel(( 'Query FIRST\'s server for function metadata.\n' 'If a function within this IDB matches a signature found in ' 'FIRST then it and its metadata will be available for you to ' 'select below to apply to your IDB. Select the function you ' 'wish to apply existing metadata to in order to view the ' 'possible matches.')) description.setWordWrap(True) description.setStyleSheet('text-size: 90%') vbox_text = QtWidgets.QVBoxLayout() vbox_text.addWidget(title) vbox_text.addWidget(description) widget = QtWidgets.QWidget() widget.setFixedWidth(100) vbox_legend = QtWidgets.QVBoxLayout(widget) grid_legend = QtWidgets.QGridLayout() style = 'background-color: #{0:06x}; border: 1px solid #c0c0c0;' colors = [FIRST.color_applied, FIRST.color_selected] text = ['Applied', 'Selected'] for i in xrange(len(colors)): box = QtWidgets.QLabel() box.setFixedHeight(10) box.setFixedWidth(10) box.setStyleSheet(style.format(colors[i].color().rgb() & 0xFFFFFF)) grid_legend.addWidget(box, i, 0) grid_legend.addWidget(QtWidgets.QLabel(text[i]), i, 1) vbox_legend.addLayout(grid_legend) vbox_legend.setAlignment(Qt.AlignRight | Qt.AlignBottom) vbox_legend.setContentsMargins(20, 0, 0, 0) self.top_layout.addLayout(vbox_text) self.top_layout.addWidget(widget)
def init_top_layout(self): title = QtWidgets.QLabel('Check Function') title.setStyleSheet('font: 16pt;') description = QtWidgets.QLabel(( 'Query FIRST\'s server for function metadata.\n' 'If a function within this IDB matches a signature found in ' 'FIRST then it and its metadata will be available for you to ' 'select below to apply to your IDB. Click to select a ' 'function\'s metadata and click again to deselect it.')) description.setWordWrap(True) description.setStyleSheet('text-size: 90%') vbox_text = QtWidgets.QVBoxLayout() vbox_text.addWidget(title) vbox_text.addWidget(description) widget = QtWidgets.QWidget() widget.setFixedWidth(100) vbox_legend = QtWidgets.QVBoxLayout(widget) grid_legend = QtWidgets.QGridLayout() style = 'background-color: #{0:06x}; border: 1px solid #c0c0c0;' colors = [FIRST.color_applied, FIRST.color_selected] text = ['Applied', 'Selected'] for i in xrange(len(colors)): box = QtWidgets.QLabel() box.setFixedHeight(10) box.setFixedWidth(10) box.setStyleSheet(style.format(colors[i].color().rgb() & 0xFFFFFF)) grid_legend.addWidget(box, i, 0) grid_legend.addWidget(QtWidgets.QLabel(text[i]), i, 1) vbox_legend.addLayout(grid_legend) vbox_legend.setAlignment(Qt.AlignRight | Qt.AlignBottom) vbox_legend.setContentsMargins(20, 0, 0, 0) self.top_layout.addLayout(vbox_text) self.top_layout.addWidget(widget)
def init_ui(self): # v.box box = QVBoxLayout() box.setSpacing(5) box2 = QHBoxLayout() l1 = QLabel('Update', self) l1.setFont(QtGui.QFont("Times", 12)) box.addWidget(l1, 0, Qt.AlignHCenter) # box.insertSpacing(1, 10) l2 = QLabel("Red:", self) box.addWidget(l2, 0, Qt.AlignLeft) self.r1 = QRadioButton("Update Red + Requirements \n(recommended)") self.r1.setChecked(True) box.addWidget(self.r1, 0, Qt.AlignLeft) self.r2 = QRadioButton("Update Red") box.addWidget(self.r2, 0, Qt.AlignLeft) self.r3 = QRadioButton("Update Requirements") box.addWidget(self.r3, 0, Qt.AlignLeft) # box.insertSpacing(1, 10) l3 = QLabel("Others:", self) box.addWidget(l3, 0, Qt.AlignLeft) self.r4 = QRadioButton("Update PIP \n(Might require admin privileges)") box.addWidget(self.r4, 0, Qt.AlignLeft) # box.insertSpacing(1, 10) b1 = QPushButton("OK", self) b1.setMinimumWidth(100) box2.addWidget(b1, 0, Qt.AlignBottom) b2 = QPushButton("Cancel", self) b2.setMinimumWidth(100) box2.addWidget(b2, 0, Qt.AlignBottom) box.setAlignment(Qt.AlignHCenter) box.addLayout(box2) self.setLayout(box) # binds b1.clicked.connect(self.ok_clicked) b2.clicked.connect(self.switchwindow) # window self.setFixedSize(220, 210) self.setWindowIcon(QtGui.QIcon('red.ico')) self.setWindowTitle('Red Bot - Update') self.show()
def init_ui(self): # v.box box = QVBoxLayout() box.setSpacing(5) box2 = QHBoxLayout() l1 = QLabel('Red Requirements', self) l1.setFont(QtGui.QFont("Times", 12)) box.addWidget(l1, 0, Qt.AlignHCenter) # box.insertSpacing(1, 10) l2 = QLabel("Main Requirements", self) box.addWidget(l2, 0, Qt.AlignLeft) self.r1 = QRadioButton("Install basic + audio requirements \n(recommended)") self.r1.setChecked(True) box.addWidget(self.r1, 0, Qt.AlignLeft) self.r2 = QRadioButton("Install basic requirements") box.addWidget(self.r2, 0, Qt.AlignLeft) # box.insertSpacing(1, 10) l3 = QLabel("FFMPEG (required for audio)", self) box.addWidget(l3, 0, Qt.AlignLeft) self.r3 = QRadioButton("Install ffmpeg 32bit") box.addWidget(self.r3, 0, Qt.AlignLeft) self.r4 = QRadioButton("Install ffmpeg 64bit") box.addWidget(self.r4, 0, Qt.AlignLeft) # box.insertSpacing(1, 10) b1 = QPushButton("OK", self) b1.setMinimumWidth(100) box2.addWidget(b1, 0, Qt.AlignBottom) b2 = QPushButton("Cancel", self) b2.setMinimumWidth(100) box2.addWidget(b2, 0, Qt.AlignBottom) box.setAlignment(Qt.AlignHCenter) box.addLayout(box2) self.setLayout(box) # binds b1.clicked.connect(self.ok_clicked) b2.clicked.connect(self.switchwindow) # window self.setFixedSize(220, 210) self.setWindowIcon(QtGui.QIcon('red.ico')) self.setWindowTitle('Red Bot - Requirements') self.show()
def init_ui(self): # v.box box = QVBoxLayout() box.setSpacing(5) box2 = QHBoxLayout() l1 = QLabel('Maintenance', self) l1.setFont(QtGui.QFont("Times", 12)) box.addWidget(l1, 0, Qt.AlignHCenter) # box.insertSpacing(1, 10) l2 = QLabel("Repair:", self) box.addWidget(l2, 0, Qt.AlignLeft) self.r1 = QRadioButton("Repair Red \n(discards code changes, keeps data intact)") self.r1.setChecked(True) box.addWidget(self.r1, 0, Qt.AlignLeft) self.r2 = QRadioButton("Wipe 'data' folder \n(all settings, cogs' data...)") box.addWidget(self.r2, 0, Qt.AlignLeft) self.r3 = QRadioButton("Wipe 'lib' folder \n(all local requirements / local installed python packages)") box.addWidget(self.r3, 0, Qt.AlignLeft) self.r4 = QRadioButton("Factory reset") box.addWidget(self.r4, 0, Qt.AlignLeft) # box.insertSpacing(1, 10) b1 = QPushButton("OK", self) b1.setMaximumWidth(100) box2.addWidget(b1, 0, Qt.AlignBottom) b2 = QPushButton("Cancel", self) b2.setMaximumWidth(100) box2.addWidget(b2, 0, Qt.AlignBottom) box.setAlignment(Qt.AlignHCenter) box.addLayout(box2) self.setLayout(box) # binds b1.clicked.connect(self.ok_clicked) b2.clicked.connect(self.switchwindow) # window self.setFixedSize(320, 210) self.setWindowIcon(QtGui.QIcon('red.ico')) self.setWindowTitle('Red Bot - Maintenance') self.show()
def init_ui(self): # v.box gbox = QtWidgets.QGridLayout() box = QtWidgets.QVBoxLayout() self.rbox = QtWidgets.QVBoxLayout() self.hbox = QtWidgets.QHBoxLayout() # padding/margins gbox.setContentsMargins(0, 0, 0, 0) self.rbox.setContentsMargins(0, 0, 10, 10) self.hbox.setContentsMargins(0, 0, 10, 10) box.addStretch() self.hbox.addStretch() gbox.setSpacing(10) box.setSpacing(0) self.rbox.setSpacing(5) self.hbox.setSpacing(0) image = QtGui.QImage() image.loadFromData(urllib.request.urlopen('http://i.imgur.com/04DUqa3.png').read()) png = QLabel(self) pixmap = QtGui.QPixmap(image) png.setPixmap(pixmap) gbox.addWidget(png, 0, 0, 1, 1, Qt.AlignTop) box.insertSpacing(1, 10) self.l1 = QLabel(self) self.l1.setWordWrap(True) self.large_font.setBold(True) self.l1.setFont(self.large_font) box.addWidget(self.l1, 0, Qt.AlignTop) hline = QtWidgets.QFrame() hline.setFrameShape(QtWidgets.QFrame.HLine) hline.setFrameShadow(QtWidgets.QFrame.Sunken) gbox.addWidget(hline, 0, 0, 1, 3, Qt.AlignBottom) # start form self.req_ui() self.rbox.setAlignment(Qt.AlignTop) box.addLayout(self.rbox, 1) gbox.addLayout(box, 0, 1, 1, 2) gbox.addLayout(self.hbox, 1, 0, 1, 3) self.setLayout(gbox) # window self.setFixedSize(490, 400) self.setWindowIcon(QtGui.QIcon('red.ico')) self.setWindowTitle('Red Discord Bot - Setup') self.show()
def prefix_ui(self): self.clear_layout(self.rbox) self.clear_layout(self.hbox) self.hbox.addStretch() self.l1.setText("Input your desired prefix") self.rbox.insertSpacing(1, 30) self.prefix_print = QLabel(self) self.prefix_print.setText('Prefix will be set to: <font color="#ff0000">!</font>' '<br>You would execute the help command by typing: ' '<font color="#ff0000">!help</font>') self.prefix_print.setWordWrap(True) self.rbox.addWidget(self.prefix_print, 0, Qt.AlignTop) self.prefix_edit = QLineEdit(self) self.prefix_edit.setPlaceholderText("!") self.prefix_edit.setMaximumWidth(300) self.rbox.addWidget(self.prefix_edit, 0, Qt.AlignTop) l2 = QLabel(self) l2.setText('\nPrefixes are referred to in the bot with [p]. ' '\nAny time you see [p], replace it with your prefix.') self.rbox.addWidget(l2, 0, Qt.AlignCenter) matches = [a for a in self.settings.prefixes] if len(matches) > 0: prefixes = ', '.join(self.settings.prefixes) if len(matches) == 1: plural = "</font>\nis your current prefix." elif len(matches) > 1: plural = "</font>\nare your current prefixes." l5 = QLabel(self) l5.setText('<font color="#ff0000">' + prefixes + plural) self.rbox.addWidget(l5, 1, Qt.AlignBottom) b5 = QPushButton("Skip", self) b5.setMaximumWidth(50) self.rbox.addWidget(b5, 0, Qt.AlignBottom) b5.clicked.connect(self.admin_ui) # buttons self.buttons_panel() # binds self.prefix_edit.textChanged[str].connect(self.prefix_on_change) self.b1.setEnabled(True) self.b1.clicked.connect(self.token_ui) self.b2.clicked.connect(self.prefix_save) self.b3.clicked.connect(self.close_prompt)
def initUI(self): """ Initialize the Central Widget user interface. """ def __get_top_layout(parent): image = ImageWidget(parent, B3_BANNER) layout = QHBoxLayout() layout.addWidget(image) layout.setAlignment(Qt.AlignTop) layout.setContentsMargins(0, 0, 0, 0) return layout def __get_middle_layout(parent): parent.main_table = MainTable(parent) parent.help_label = HelpLabel(parent.main_table) layout = QVBoxLayout() layout.addWidget(parent.main_table) #layout.addWidget(parent.help_label) layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop) layout.setContentsMargins(0, 2, 0, 0) return layout def __get_bottom_layout(parent): parent.news = MarqueeLabel(parent) parent.news.parseFeed() btn_new = Button(parent=parent, text='Add', shortcut='Ctrl+N') btn_new.clicked.connect(self.parent().new_process_dialog) btn_new.setStatusTip('Add a new B3') btn_new.setVisible(True) btn_quit = Button(parent=parent, text='Quit', shortcut='Ctrl+Q') btn_quit.clicked.connect(B3App.Instance().shutdown) btn_quit.setStatusTip('Shutdown B3') btn_quit.setVisible(True) layout = QHBoxLayout() layout.addWidget(parent.news) layout.addWidget(btn_new) layout.addWidget(btn_quit) layout.setAlignment(Qt.AlignBottom | Qt.AlignRight) layout.setSpacing(10) layout.setContentsMargins(0, 0, 11, GEOMETRY[b3.getPlatform()]['CENTRAL_WIDGET_BOTTOM_LAYOUT_MARGIN_BOTTOM']) return layout main_layout = QVBoxLayout() main_layout.addLayout(__get_top_layout(self)) main_layout.addLayout(__get_middle_layout(self)) main_layout.addLayout(__get_bottom_layout(self)) main_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(main_layout) self.setFixedSize(614, 512) self.setStyleSheet(""" QWidget, QDialog, QMessageBox { background: #F2F2F2; } """) self.setFocus()