def __init__(self, program: Program): super().__init__() self._program = program parametersLabel = QLabel("Parameters") newParameterButton = QPushButton("Add Parameter") newParameterButton.clicked.connect(self.AddParameter) layout = QVBoxLayout() titleLayout = QHBoxLayout() titleLayout.addWidget(parametersLabel) titleLayout.addWidget(newParameterButton) layout.addLayout(titleLayout) self._listArea = QScrollArea() self._listArea.setWidgetResizable(True) self._listArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self._listArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) layout.addWidget(self._listArea, stretch=1) listWidget = QWidget() self._itemLayout = QVBoxLayout() self._itemLayout.setAlignment(Qt.AlignTop) listWidget.setLayout(self._itemLayout) self.setLayout(layout) self._listArea.setWidget(listWidget) self.items: List[ParameterEditorItem] = [] self._temporaryParameters = program.parameters.copy() self.Populate()
def __init__(self, base, name, callback, *args, **kwargs): TritonWidget.__init__(self, base, *args, **kwargs) self.callback = callback self.setWindowTitle(name) self.setBackgroundColor(self, Qt.white) self.boxLayout = QVBoxLayout(self) self.boxLayout.setContentsMargins(0, 5, 0, 0) layout = None for i, icon in enumerate(os.listdir('icons')): if (not layout) or i % 10 == 0: widget = QWidget() layout = QHBoxLayout(widget) layout.setContentsMargins(5, 5, 5, 5) self.boxLayout.addWidget(widget) name = os.path.join('icons', icon) button = PixmapButton(QPixmap(name).scaled(48, 48)) button.clicked.connect(self.makeIconCallback(name)) button.setToolTip(icon) layout.addWidget(button) self.setFixedSize(self.sizeHint()) self.center() self.show()
class WidgetContent(QWidget): def __init__(self, mdi): super(WidgetContent, self).__init__() self.mdi = mdi self.layout = QHBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) self.setLayout(self.layout) self.menu_btn = QPushButton("Menu") self.menu_btn.clicked.connect(self.show_menu) self.layout.addWidget(self.menu_btn) def show_menu(self): self.animation = QPropertyAnimation(self.mdi.menu, b"size") self.animation.setDuration(150) self.animation.setStartValue(QSize(0, self.mdi.height())) self.animation.setEndValue(QSize(270, self.mdi.height())) self.animation.start() self.mdi.overlay.show() self.mdi.menu.show() self.mdi.setActiveSubWindow(self.mdi.overlay) self.mdi.setActiveSubWindow(self.mdi.menu) def paintEvent(self, event): opt = QStyleOption() opt.initFrom(self) p = QPainter(self) self.style().drawPrimitive(QStyle.PE_Widget, opt, p, self)
def initUI(self): self.setWindowTitle("QTableWidget demo") self.resize(500, 300); conLayout = QHBoxLayout() self.tableWidget = QTableWidget() self.tableWidget.setRowCount(5) self.tableWidget.setColumnCount(3) conLayout.addWidget(self.tableWidget) self.tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重']) self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) newItem = QTableWidgetItem("张三") self.tableWidget.setItem(0, 0, newItem) newItem = QTableWidgetItem("男") self.tableWidget.setItem(0, 1, newItem) newItem = QTableWidgetItem("160") self.tableWidget.setItem(0, 2, newItem) # 表格中第二行记录 newItem = QTableWidgetItem("李四") self.tableWidget.setItem(1, 0, newItem) newItem = QTableWidgetItem("女") self.tableWidget.setItem(1, 1, newItem) newItem = QTableWidgetItem("170") self.tableWidget.setItem(1, 2, newItem) self.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu) ######允许右键产生子菜单 self.tableWidget.customContextMenuRequested.connect(self.generateMenu) ####右键菜单 self.setLayout(conLayout)
def initUI(self): self.setWindowTitle("QTableWidget 例子") self.resize(430, 300); conLayout = QHBoxLayout() tableWidget = QTableWidget() tableWidget.setRowCount(4) tableWidget.setColumnCount(3) conLayout.addWidget(tableWidget) tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重(kg)']) newItem = QTableWidgetItem("张三") tableWidget.setItem(0, 0, newItem) comBox = QComboBox() comBox.addItem("男") comBox.addItem("女") comBox.setStyleSheet("QComboBox{margin:3px};") tableWidget.setCellWidget(0, 1, comBox) searchBtn = QPushButton("修改") searchBtn.setDown(True) searchBtn.setStyleSheet("QPushButton{margin:3px};") tableWidget.setCellWidget(0, 2, searchBtn) self.setLayout(conLayout)
def __init__(self): super(Window, self).__init__() self.installEventFilter(self) layout = QHBoxLayout() layout.setSpacing(0) layout.setContentsMargins(10, 10, 10, 10) layout.addWidget(self.createMainSection()) layout.setStretch(0, 580) self.patchbay = self.createPatchbay() layout.addWidget(self.patchbay) layout.setStretch(1, 280) layout.setSpacing(8) self.setStyleSheet(mainWindowStyleSheet()) centralWidget = QWidget(self) self.setCentralWidget(centralWidget) centralWidget.setLayout(layout) self.setWindowTitle("Sharm v2") path = join("gui", "images", "icon.svg") self.setWindowIcon(QtGui.QIcon(path)) # self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint) self.setFocus()
class OptionalCurrencyComboBox(QWidget): changed = Signal() name_updated = Signal(str) def __init__(self, parent): QWidget.__init__(self, parent) self._id = 0 self.layout = QHBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.null_flag = QCheckBox(parent) self.null_flag.setChecked(False) self.null_flag.setText(self.tr("Currency")) self.layout.addWidget(self.null_flag) self.currency = CurrencyComboBox(parent) self.currency.setEnabled(False) self.layout.addWidget(self.currency) self.setLayout(self.layout) self.setFocusProxy(self.null_flag) self.null_flag.clicked.connect(self.onClick) self.currency.changed.connect(self.onCurrencyChange) def setText(self, text): self.null_flag.setText(text) def getId(self): return self._id if self._id else None def setId(self, new_value): if self._id == new_value: return self._id = new_value self.updateView() name = JalDB().get_asset_name(self._id) self.name_updated.emit('' if name is None else name) currency_id = Property(int, getId, setId, notify=changed, user=True) def updateView(self): has_value = True if self._id else False if has_value: self.currency.selected_id = self._id self.null_flag.setChecked(has_value) self.currency.setEnabled(has_value) @Slot() def onClick(self): if self.null_flag.isChecked(): if self.currency.selected_id == 0: self.currency.selected_id = JalSettings().getValue('BaseCurrency') self.currency_id = self.currency.selected_id else: self.currency_id = 0 self.changed.emit() @Slot() def onCurrencyChange(self, _id): self.currency_id = self.currency.selected_id self.changed.emit()
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle("My App") layout1 = QHBoxLayout() layout2 = QVBoxLayout() layout3 = QVBoxLayout() layout2.addWidget(Color("red")) layout2.addWidget(Color("yellow")) layout2.addWidget(Color("purple")) layout1.addLayout(layout2) layout1.addWidget(Color('green')) layout3.addWidget(Color("red")) layout3.addWidget(Color("purple")) layout1.addLayout(layout3) widget = QWidget() widget.setLayout(layout1) self.setCentralWidget(widget)
def __init__(self, parent: QWidget, parent_layout: QVBoxLayout, line_layout: QHBoxLayout, resource_database: ResourceDatabase, requirement: RequirementArrayBase): self._editors = [] self.resource_database = resource_database self._array_type = type(requirement) # the parent is added to a layout which is added to parent_layout, so we index = parent_layout.indexOf(line_layout) + 1 self.group_box = QGroupBox(parent) self.group_box.setStyleSheet("QGroupBox { margin-top: 2px; }") parent_layout.insertWidget(index, self.group_box) self.item_layout = QVBoxLayout(self.group_box) self.item_layout.setContentsMargins(8, 2, 2, 6) self.item_layout.setAlignment(Qt.AlignTop) self.new_item_button = QPushButton(self.group_box) self.new_item_button.setMaximumWidth(75) self.new_item_button.setText("New Row") self.new_item_button.clicked.connect(self.new_item) self.comment_text_box = QLineEdit(parent) self.comment_text_box.setText(requirement.comment or "") self.comment_text_box.setPlaceholderText("Comment") line_layout.addWidget(self.comment_text_box) for item in requirement.items: self._create_item(item) self.item_layout.addWidget(self.new_item_button)
def __init__(self): super(MainWindow, self).__init__() # 左边的菜单项 menu_widget = QListWidget() for i in range(10): item = QListWidgetItem(f"item {i}") item.setTextAlignment(Qt.AlignCenter) menu_widget.addItem(item) _placeholder = "text_widget" text_widget = QLabel(_placeholder) button = QPushButton("Click") # 横向布局 content_layout = QVBoxLayout() content_layout.addWidget(text_widget) content_layout.addWidget(button) main_widget = QWidget() main_widget.setLayout(content_layout) layout = QHBoxLayout() layout.addWidget(menu_widget, 1) layout.addWidget(main_widget, 4) self.setLayout(layout)
def initUI(self): """ Init widget """ vbox = QVBoxLayout() vbox.addSpacing(2) # Head hbox = QHBoxLayout() hbox.addSpacing(2) # Create button which returns to the menu self._buttonBack = QPushButton(QIcon(PATH_IMAGE_BACK_NEDDLE), "", self) self._buttonBack.clicked.connect(self.signalController.back2menu) hbox.addWidget(self._buttonBack, 0, QtCore.Qt.AlignLeft) # Header of this widget self._headWidget = QLabel("About game") hbox.addWidget(self._headWidget, 1, QtCore.Qt.AlignCenter) vbox.addLayout(hbox, 0) # Create text about game text = ABOUT_GAME_STR self.textAboutGame = QLabel(text) self.textAboutGame.setWordWrap(True) self.setFont(QFont("Times", 12, QFont.Bold)) vbox.addWidget(self.textAboutGame, 1, QtCore.Qt.AlignCenter) self.setLayout(vbox) self.setWindowTitle("About game")
class View(QWidget): def __init__(self): super().__init__() self.layout = QHBoxLayout(self) self.selected = None self.pixmap_cache = {} # The split view at first shows the list of manga items and the default item view. # After a manga has been selected, there will be a total of three widgets: # - Manga item list # - Manga description # - Manga info (incl. cover) self.layout.addWidget(MANGA_ITEMS) self.layout.addWidget(self.default()) MANGA_ITEMS.itemClicked.connect(self.onSelectedManga) def default(self): label = QLabel("Select a manga from the side bar, or add a new one.") label.setAlignment(Qt.AlignCenter) return label def deleteLast(self): while self.layout.count() != 1: delete(self.layout.takeAt(1)) def onSelectedManga(self, manga_item): self.deleteLast() self.selected = manga_item manga = _load_manga(manga_item.meta.hash) summary = SummaryView(manga) self.layout.addWidget(summary) infobox = ItemInfoBox(manga_item) scroll = QScrollArea() scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setFrameShape(scroll.NoFrame) scroll.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) scroll.setWidget(infobox) self.layout.addWidget(scroll) def onDeletedManga(self): self.deleteLast() self.layout.addWidget(self.default()) def reload(self): if self.selected is not None: self.onSelectedManga(self.selected) else: # no manga selected yet. self.onDeletedManga()
def __init__(self, persepolis_setting): super().__init__() icon = QIcon() self.persepolis_setting = persepolis_setting # add support for other languages locale = str(self.persepolis_setting.value('settings/locale')) QLocale.setDefault(QLocale(locale)) self.translator = QTranslator() if self.translator.load(':/translations/locales/ui_' + locale, 'ts'): QCoreApplication.installTranslator(self.translator) self.setWindowIcon( QIcon.fromTheme('persepolis', QIcon(':/persepolis.svg'))) self.setWindowTitle( QCoreApplication.translate("setting_ui_tr", 'Preferences')) # set ui direction ui_direction = self.persepolis_setting.value('ui_direction') if ui_direction == 'rtl': self.setLayoutDirection(Qt.RightToLeft) elif ui_direction in 'ltr': self.setLayoutDirection(Qt.LeftToRight) global icons icons = ':/' + str( self.persepolis_setting.value('settings/icons')) + '/' window_verticalLayout = QVBoxLayout(self) self.pressKeyLabel = QLabel(self) window_verticalLayout.addWidget(self.pressKeyLabel) self.capturedKeyLabel = QLabel(self) window_verticalLayout.addWidget(self.capturedKeyLabel) # window buttons buttons_horizontalLayout = QHBoxLayout() buttons_horizontalLayout.addStretch(1) self.cancel_pushButton = QPushButton(self) self.cancel_pushButton.setIcon(QIcon(icons + 'remove')) buttons_horizontalLayout.addWidget(self.cancel_pushButton) self.ok_pushButton = QPushButton(self) self.ok_pushButton.setIcon(QIcon(icons + 'ok')) buttons_horizontalLayout.addWidget(self.ok_pushButton) window_verticalLayout.addLayout(buttons_horizontalLayout) # labels self.pressKeyLabel.setText( QCoreApplication.translate("setting_ui_tr", "Press new keys")) self.cancel_pushButton.setText( QCoreApplication.translate("setting_ui_tr", "Cancel")) self.ok_pushButton.setText( QCoreApplication.translate("setting_ui_tr", "OK"))
def __init__(self, program: Program): super().__init__() AppGlobals.Instance().onChipOpened.connect(self.CheckForProgram) AppGlobals.Instance().onChipModified.connect(self.CheckForProgram) self.program = program self.modified = False self.codeEditor = CodeTextEditor() layout = QHBoxLayout() self.setLayout(layout) self._programNameField = QLineEdit(program.name) self._programNameField.textChanged.connect(self.UpdateProgramName) self._parameterEditor = ParameterEditor(program) self._parameterEditor.onParametersChanged.connect(self.ProgramEdited) programNameLabel = QLabel("Name:") sideLayout = QVBoxLayout() sideLayout.addWidget(programNameLabel) sideLayout.addWidget(self._programNameField) sideLayout.addWidget(self._parameterEditor) layout.addLayout(sideLayout, stretch=0) layout.addWidget(self.codeEditor, stretch=1) self.codeEditor.SetCode(self.program.script) self.codeEditor.codeChanged.connect(self.ProgramEdited)
def setup_ui(self, win: QMainWindow) -> None: # ui widgets self.toolbar = QToolBar("main", parent=win) self.port_combobox1 = PortCombobox("") self.port_combobox2 = PortCombobox("") self.baudrate_combobox = QComboBox() self.monitor1 = QPlainTextEdit("") self.monitor2 = QPlainTextEdit("") self.btn_clear_monitor1 = QPushButton("Clear") self.btn_clear_monitor2 = QPushButton("Clear") self.group_monitor1 = QGroupBox("Monitor 1") self.group_monitor2 = QGroupBox("Monitor 2") # setup widgets self.monitor1.setReadOnly(True) self.monitor1.setLineWrapMode(QPlainTextEdit.NoWrap) self.monitor1.setUndoRedoEnabled(False) self.monitor2.setReadOnly(True) self.monitor2.setLineWrapMode(QPlainTextEdit.NoWrap) self.monitor2.setUndoRedoEnabled(False) self.baudrate_combobox.addItems([ "300", "1200", "2400", "4800", "9600", "19200", "38400", "57600", "74880", "115200", "230400", "250000", "500000", "1000000", "2000000", ]) self.baudrate_combobox.setCurrentText("9600") # setup layout win.addToolBar(self.toolbar) v_layout = QVBoxLayout() # type:ignore v_layout.addWidget(self.monitor1) v_layout.addWidget(self.btn_clear_monitor1) self.group_monitor1.setLayout(v_layout) v_layout = QVBoxLayout() # type:ignore v_layout.addWidget(self.monitor2) v_layout.addWidget(self.btn_clear_monitor2) self.group_monitor2.setLayout(v_layout) h_layout = QHBoxLayout() # type:ignore h_layout.addWidget(self.group_monitor1) h_layout.addWidget(self.group_monitor2) central_widget = QWidget() central_widget.setLayout(h_layout) win.setCentralWidget(central_widget)
def tab_microenv(self): layout = QFormLayout() sex = QHBoxLayout() sex.addWidget(QRadioButton("Male")) sex.addWidget(QRadioButton("Female")) layout.addRow(QLabel("Sex"), sex) layout.addRow("Date of Birth", QLineEdit()) # self.setTabText(1,"Microenvironment") self.tab2.setLayout(layout)
class Page2Widget(QWidget): def __init__(self): super().__init__() self.layout = QHBoxLayout(self) self.ans_buttons = [] for i in range(3): self.ans_buttons.append(QPushButton(FixedHeight=70)) self.layout.addWidget(self.ans_buttons[i])
def __init__(self, parent, persepolis_setting): super().__init__(parent) self.persepolis_setting = persepolis_setting # set ui direction ui_direction = self.persepolis_setting.value('ui_direction') if ui_direction == 'rtl': self.setLayoutDirection(Qt.RightToLeft) elif ui_direction in 'ltr': self.setLayoutDirection(Qt.LeftToRight) # set size self.resize(QSize(400, 80)) self.setFixedWidth(400) # show this widget as ToolTip widget self.setWindowFlags(Qt.ToolTip) # find bottom right position bottom_right_screen = QDesktopWidget().availableGeometry().bottomRight( ) bottom_right_notification = QRect(QPoint(0, 0), QSize(410, 120)) bottom_right_notification.moveBottomRight(bottom_right_screen) self.move(bottom_right_notification.topLeft()) # get persepolis icon path icons = ':/' + \ str(self.persepolis_setting.value('settings/icons')) + '/' notification_horizontalLayout = QHBoxLayout(self) # persepolis icon svgWidget = QtSvg.QSvgWidget(':/persepolis.svg') svgWidget.setFixedSize(QSize(64, 64)) notification_horizontalLayout.addWidget(svgWidget) notification_verticalLayout = QVBoxLayout() # 2 labels for notification messages self.label1 = QLabel(self) self.label1.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) self.label1.setStyleSheet("font-weight: bold") self.label1.setWordWrap(True) self.label2 = QLabel(self) self.label2.setWordWrap(True) self.label2.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) notification_verticalLayout.addWidget(self.label1) notification_verticalLayout.addWidget(self.label2) notification_horizontalLayout.addLayout(notification_verticalLayout)
def __init__(self, parent=None): super().__init__("Stats", parent=parent) self.fps_label = QLabel("0 fps") layout = QHBoxLayout() self.setLayout(layout) layout.addWidget(QLabel("Refresh rate:")) layout.addWidget(self.fps_label)
class ChartWidget(QWidget): def __init__(self, parent, quotes, trades, data_range, currency_name): QWidget.__init__(self, parent) self.setMinimumWidth(600) self.setMinimumHeight(400) self.quotes_series = QLineSeries() for point in quotes: # Conversion to 'float' in order not to get 'int' overflow on some platforms self.quotes_series.append(float(point['timestamp']), point['quote']) self.trade_series = QScatterSeries() for point in trades: # Conversion to 'float' in order not to get 'int' overflow on some platforms self.trade_series.append(float(point['timestamp']), point['price']) self.trade_series.setMarkerSize(5) self.trade_series.setBorderColor(CustomColor.LightRed) self.trade_series.setBrush(CustomColor.DarkRed) axisX = QDateTimeAxis() axisX.setTickCount(11) axisX.setRange(QDateTime().fromSecsSinceEpoch(data_range[0]), QDateTime().fromSecsSinceEpoch(data_range[1])) axisX.setFormat("yyyy/MM/dd") axisX.setLabelsAngle(-90) axisX.setTitleText("Date") axisY = QValueAxis() axisY.setTickCount(11) axisY.setRange(data_range[2], data_range[3]) axisY.setTitleText("Price, " + currency_name) self.chartView = QChartView() self.chartView.chart().addSeries(self.quotes_series) self.chartView.chart().addSeries(self.trade_series) self.chartView.chart().addAxis(axisX, Qt.AlignBottom) self.chartView.chart().setAxisX(axisX, self.quotes_series) self.chartView.chart().setAxisX(axisX, self.trade_series) self.chartView.chart().addAxis(axisY, Qt.AlignLeft) self.chartView.chart().setAxisY(axisY, self.quotes_series) self.chartView.chart().setAxisY(axisY, self.trade_series) self.chartView.chart().legend().hide() self.chartView.setViewportMargins(0, 0, 0, 0) self.chartView.chart().layout().setContentsMargins( 0, 0, 0, 0) # To remove extra spacing around chart self.chartView.chart().setBackgroundRoundness( 0) # To remove corner rounding self.chartView.chart().setMargins(QMargins( 0, 0, 0, 0)) # Allow chart to fill all space self.layout = QHBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) # Remove extra space around layout self.layout.addWidget(self.chartView) self.setLayout(self.layout)
def __init__(self): super(MainWindow, self).__init__() hBoxLayout = QHBoxLayout(self) self.plainTextEdit = QPlainTextEdit() self.plainTextEdit.setMinimumWidth(400) self.plainTextEdit.setReadOnly(True) hBoxLayout.addWidget(self.plainTextEdit) self.renderWindow = RenderWindow(QSurfaceFormat()) container = QWidget.createWindowContainer(self.renderWindow) container.setMinimumSize(QSize(400, 400)) hBoxLayout.addWidget(container)
def __init__(self, parent, rows, selected=None, disabled=None): super().__init__(parent) self.setWindowTitle("Select XDF Stream") self.model = QStandardItemModel() self.model.setHorizontalHeaderLabels( ["ID", "Name", "Type", "Channels", "Format", "Sampling Rate"]) for index, stream in enumerate(rows): items = [] for item in stream: tmp = QStandardItem() tmp.setData(item, Qt.DisplayRole) items.append(tmp) for item in items: item.setEditable(False) if disabled is not None and index in disabled: item.setFlags(Qt.NoItemFlags) self.model.appendRow(items) self.view = QTableView() self.view.setModel(self.model) self.view.verticalHeader().setVisible(False) self.view.horizontalHeader().setStretchLastSection(True) self.view.setShowGrid(False) self.view.setSelectionMode(QAbstractItemView.SingleSelection) self.view.setSelectionBehavior(QAbstractItemView.SelectRows) if selected is not None: self.view.selectRow(selected) self.view.setSortingEnabled(True) self.view.sortByColumn(0, Qt.AscendingOrder) vbox = QVBoxLayout(self) vbox.addWidget(self.view) hbox = QHBoxLayout() self._effective_srate = QCheckBox("Use effective sampling rate") self._effective_srate.setChecked(True) hbox.addWidget(self._effective_srate) self._prefix_markers = QCheckBox("Prefix markers with stream ID") self._prefix_markers.setChecked(False) if not disabled: self._prefix_markers.setEnabled(False) hbox.addWidget(self._prefix_markers) vbox.addLayout(hbox) self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) vbox.addWidget(self.buttonbox) self.buttonbox.accepted.connect(self.accept) self.buttonbox.rejected.connect(self.reject) self.resize(775, 650) self.view.setColumnWidth(0, 90) self.view.setColumnWidth(1, 200) self.view.setColumnWidth(2, 140)
def __init__(self): super().__init__() self.layout = QHBoxLayout() i = 0 self.names = [] self.ebutons = [] self.dbutons = [] folder = './saved' #-------------Loading saved images from ./saved------------ if (len(os.listdir(folder)) == 0): #print oput nothing saved self.label = QLabel("Nothing Saved") self.layout.addWidget(self.label) else: for filename in os.listdir(folder): self.names.append(filename) self.ebutons.append(i) self.dbutons.append(i) lay = QVBoxLayout() gbox = QGroupBox('Result' + str(i + 1)) path = folder + "/" + filename with open(path, 'rb') as thefile: imag = pickle.load(thefile) path += ".jpg" im = Image.open( requests.get(imag['urls']['thumb'], stream=True).raw) im.save(path) self.ebutons[i] = QPushButton("Edit") self.ebutons[i].clicked.connect( lambda state=i, a=i: self.editme(state)) self.dbutons[i] = QPushButton("Delete") self.dbutons[i].clicked.connect( lambda state=i, a=i: self.deleteme(state)) pixmap = QPixmap(path) self.image = QLabel() self.image.setPixmap(pixmap) lay.addWidget(self.image) buts = QHBoxLayout() buts.addWidget(self.ebutons[i]) buts.addWidget(self.dbutons[i]) lay.addLayout(buts) gbox.setLayout(lay) self.layout.addWidget(gbox) try: if os.path.isfile(path) or os.path.islink(path): os.unlink(path) elif os.path.isdir(path): shutil.rmtree(path) except Exception as e: print('Failed to delete %s. Reason: %s' % (file_path, e)) i += 1 print("done") self.setLayout(self.layout)
def createBottomControls(self): widget = QWidget() layout = QHBoxLayout() layout.addWidget(self.createGeneralSection()) layout.addWidget(self.createFilterSection()) layout.setContentsMargins(0, 0, 0, 0) widget.setContentsMargins(0, 0, 0, 0) widget.setLayout(layout) return widget
def set_item_data(self, i, DisplayName, name, sid): check_box_layout = QHBoxLayout() check_box_layout.setAlignment(Qt.AlignmentFlag.AlignCenter) check_box = QCheckBox() check_box.setObjectName('check_box_' + str(i)) check_box_layout.addWidget(check_box) check_box_layout.setContentsMargins(0, 0, 0, 0) check_box_widget = QWidget() check_box_widget.setLayout(check_box_layout) self.tableWidget.item(i, 2).setText(DisplayName) self.tableWidget.item(i, 3).setText(name) self.tableWidget.item(i, 4).setText(sid) self.tableWidget.setCellWidget(i, 0, check_box_widget)
def __init__(self, parent, init_label, mainfunction, quitfunction): super().__init__(parent) self.button = QPushButton(init_label) self.button.clicked.connect(mainfunction) self.button.setAutoDefault(True) quitbutton = QPushButton('終わる') quitbutton.setStyleSheet('background-color: #c00; color: white;') quitbutton.clicked.connect(quitfunction) layout = QHBoxLayout() layout.addWidget(self.button) layout.addWidget(quitbutton) self.setLayout(layout)
def __init__(self, name): global instance_id GlobalAreaWidget.__init__(self, name) self.actionHandler = UIActionHandler() self.actionHandler.setupActionHandler(self) offset_layout = QHBoxLayout() offset_layout.addWidget(QLabel("Offset: ")) self.offset = QLabel(hex(0)) offset_layout.addWidget(self.offset) offset_layout.setAlignment(QtCore.Qt.AlignCenter) datatype_layout = QHBoxLayout() datatype_layout.addWidget(QLabel("Data Type: ")) self.datatype = QLabel("") datatype_layout.addWidget(self.datatype) datatype_layout.setAlignment(QtCore.Qt.AlignCenter) layout = QVBoxLayout() title = QLabel(name, self) title.setAlignment(QtCore.Qt.AlignCenter) instance = QLabel("Instance: " + str(instance_id), self) instance.setAlignment(QtCore.Qt.AlignCenter) layout.addStretch() layout.addWidget(title) layout.addWidget(instance) layout.addLayout(datatype_layout) layout.addLayout(offset_layout) layout.addStretch() self.setLayout(layout) instance_id += 1 self.data = None
def test_pixmap_vertical(pixmap_differ: PixmapDiffer): actual: QPainter expected: QPainter with pixmap_differ.create_painters( 300, 240, 'scaled_label_pixmap_vertical') as (actual, expected): ex_widget = QWidget() ex_widget.resize(300, 240) expected.drawPixmap(0, 0, ex_widget.grab()) icon = GridDisplay.create_icon(GridDisplay.player2_colour) expected.drawPixmap( 0, 0, icon.scaled(150, 150, Qt.KeepAspectRatio, Qt.SmoothTransformation)) expected.drawPixmap( 150, 70, icon.scaled(100, 100, Qt.KeepAspectRatio, Qt.SmoothTransformation)) expected.drawPixmap( 250, 190, icon.scaled(50, 50, Qt.KeepAspectRatio, Qt.SmoothTransformation)) widget = QWidget() layout = QHBoxLayout(widget) label1 = ScaledLabel() label2 = ScaledLabel() label3 = ScaledLabel() label1.setPixmap(icon) label2.setPixmap(icon) label3.setPixmap(icon) size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) label1.setSizePolicy(size_policy) label2.setSizePolicy(size_policy) label3.setSizePolicy(size_policy) label1.setScaledContents(True) label2.setScaledContents(True) label3.setScaledContents(True) label1.setAlignment(Qt.AlignTop) label2.setAlignment(Qt.AlignCenter) label3.setAlignment(Qt.AlignBottom) layout.addWidget(label1) layout.addWidget(label2) layout.addWidget(label3) layout.setStretch(0, 3) layout.setStretch(1, 2) layout.setStretch(2, 1) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) widget.resize(300, 240) actual.drawPixmap(0, 0, widget.grab())
def initUI(self): self.cam = CamImage() self.start_button = QPushButton("Start") self.quit_button = QPushButton("Quit") controls = ControlWidget() self.combo = QComboBox(self) for it in self.MainProcess.list_of_filters: self.combo.addItem(it[0]) hbox = QHBoxLayout() hbox.addWidget(controls) hbox.addStretch(1) hbuttons = QHBoxLayout() hbuttons.addWidget(self.combo) hbuttons.addWidget(self.start_button) hbuttons.addWidget(self.quit_button) vbutton = QVBoxLayout() vbutton.addLayout(hbuttons) vbutton.addWidget(self.fps_label) hbox.addLayout(vbutton) vbox = QVBoxLayout() vbox.addWidget(self.cam) vbox.addStretch(1) vbox.addLayout(hbox) self.setLayout(vbox) self.setGeometry(300, 300, 300, 150) self.setWindowTitle('Buttons') self.show()
def __create_cell(self) -> QWidget: cell_label = QLabel() cell_label.setAlignment(Qt.AlignCenter) cell_label.setStyleSheet("QLabel {font-size: " + str(self._font_size) + "px;}") cell_content = QHBoxLayout() cell_content.addWidget(cell_label) cell = QWidget() cell.setLayout(cell_content) cell.setStyleSheet( f"background-color:{self._default_bg_color}; color:{self._default_color};" ) cell.setFixedSize(self.board_size, self.board_size) return cell