def __init__(self): super().__init__() # Declare Widgets self.edit_label = QLabel('Change your image') # set up list and combo box option self.my_list = ["Pick a value", "Luminosity", "Contrast", "Colorize", "Sepia", "Negative", "Grayscale", "None"] self.my_combo_box = QComboBox() self.my_combo_box.addItems(self.my_list) self.edit_btn = QPushButton("Edit") self.cancel_btn = QPushButton("Back") # Create U.I. Layout vbox = QVBoxLayout() vbox.addWidget(self.edit_label) vbox.addWidget(self.my_combo_box) vbox.addWidget(self.edit_btn) vbox.addWidget(self.cancel_btn) self.setLayout(vbox) # apply layout to this class # when button is clicked send lineedit and combo box info to on_submit self.edit_btn.clicked.connect(self.on_edit) self.cancel_btn.clicked.connect(self.on_back)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle('PySide6 WebEngineWidgets Example') self.toolBar = QToolBar() self.addToolBar(self.toolBar) self.backButton = QPushButton() self.backButton.setIcon(QIcon(':/qt-project.org/styles/commonstyle/images/left-32.png')) self.backButton.clicked.connect(self.back) self.toolBar.addWidget(self.backButton) self.forwardButton = QPushButton() self.forwardButton.setIcon(QIcon(':/qt-project.org/styles/commonstyle/images/right-32.png')) self.forwardButton.clicked.connect(self.forward) self.toolBar.addWidget(self.forwardButton) self.addressLineEdit = QLineEdit() self.addressLineEdit.returnPressed.connect(self.load) self.toolBar.addWidget(self.addressLineEdit) self.webEngineView = QWebEngineView() self.setCentralWidget(self.webEngineView) initialUrl = 'http://qt.io' self.addressLineEdit.setText(initialUrl) self.webEngineView.load(QUrl(initialUrl)) self.webEngineView.page().titleChanged.connect(self.setWindowTitle) self.webEngineView.page().urlChanged.connect(self.urlChanged)
def PreviewWindow(self): self.statusBar().showMessage('Tablecloth preview generated.') self.statusBar().removeWidget(self.progress_bar) # Now you can go back to rigging self.ChangeAppStatus(True) self.preview_wid = QWidget() self.preview_wid.resize(600, 600) self.preview_wid.setWindowTitle("Tablecloth preview") tablecloth = QPixmap(tempfile.gettempdir()+"\\Table_Dif.jpg") tablecloth_preview_title = QLabel(self) tablecloth_preview_title.setText("Tablecloth preview (1/4 scale)") tablecloth_preview = QLabel(self) tablecloth_preview.setPixmap(tablecloth.scaled(512,512)) confirm = QPushButton(self) confirm.setText("Confirm") confirm.clicked.connect(self.GenerateImage) confirm.clicked.connect(self.preview_wid.close) vbox = QVBoxLayout() vbox.setAlignment(QtCore.Qt.AlignCenter) vbox.addWidget(tablecloth_preview_title) vbox.addWidget(tablecloth_preview) vbox.addWidget(confirm) self.preview_wid.setLayout(vbox) self.preview_wid.setWindowModality(QtCore.Qt.ApplicationModal) self.preview_wid.activateWindow() self.preview_wid.raise_() self.preview_wid.show()
def init_ui(self): self.tuple_method = ("Connect to Server", "Connect to /dev") self.combobox = QComboBox() self.combobox.addItems(self.tuple_method) self.addr_edit = QLineEdit() self.port_edit = QLineEdit() self.btn_open_conn = QPushButton("Connect/Open") self.btn_close_conn = QPushButton("Close Conn") self.fd = None self.method_layout = QVBoxLayout() self.method_layout.addWidget(self.combobox) self.method_layout.addWidget(self.addr_edit) self.method_layout.addWidget(self.port_edit) self.method_layout.addWidget(self.btn_open_conn) self.method_layout.addWidget(self.btn_close_conn) self.btn_status = QPushButton("Send Status Packet") self.btn_head = QPushButton("Send Head Packet") self.btn_motion = QPushButton("Send Motion Packet") self.packet_layout = QVBoxLayout() self.packet_layout.addWidget(self.btn_status) self.packet_layout.addWidget(self.btn_head) self.packet_layout.addWidget(self.btn_motion) self.main_layout = QVBoxLayout() self.main_layout.addLayout(self.method_layout) self.main_layout.addLayout(self.packet_layout) self.setLayout(self.main_layout) self.set_send_btn_statu(False)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle("My App") pagelayout = QVBoxLayout() button_layout = QHBoxLayout() self.stacklayout = QStackedLayout() pagelayout.addLayout(button_layout) pagelayout.addLayout(self.stacklayout) btn = QPushButton("red") btn.pressed.connect(self.activate_tab_1) button_layout.addWidget(btn) self.stacklayout.addWidget(Color("red")) btn = QPushButton("green") btn.pressed.connect(self.activate_tab_2) button_layout.addWidget(btn) self.stacklayout.addWidget(Color("green")) btn = QPushButton("yellow") btn.pressed.connect(self.activate_tab_3) button_layout.addWidget(btn) self.stacklayout.addWidget(Color("yellow")) widget = QWidget() widget.setLayout(pagelayout) self.setCentralWidget(widget)
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) -> None: super().__init__() self.resize(500, 300) # 非组件对象 self.values = {} self.ut = UpdateValues() # 界面组件对象 self.centralwidget = QWidget(self) self.table = QTableWidget(self.centralwidget) self.startButton = QPushButton(self.centralwidget, text='开始') self.stopButton = QPushButton(self.centralwidget, text='停止') self.stopButton.setDisabled(True) self.table.setColumnCount(3) self.table.setHorizontalHeaderItem(0, QTableWidgetItem('GID')) self.table.setHorizontalHeaderItem(2, QTableWidgetItem('name')) self.table.setHorizontalHeaderItem(1, QTableWidgetItem('speed')) self.table.horizontalHeader().setStretchLastSection(True) self.table.setRowCount(1) self.layout = QGridLayout(self.centralwidget) self.layout.addWidget(self.startButton) self.layout.addWidget(self.stopButton) self.layout.addWidget(self.table) self.setCentralWidget(self.centralwidget) self.ut.resultReady.connect(self.on_changeValue) self.startButton.clicked.connect(self.changeValue) self.stopButton.clicked.connect(self.stopUpdate)
def create_data_group(self): """Creates group for holding specific choice data selection""" button_group = QButtonGroup(self) button_group.setExclusive(True) colecao_radio_button = QRadioButton('Coleção') self.partidas_radio_button = QRadioButton('Partidas') colecao_radio_button.setChecked(True) button_group.addButton(colecao_radio_button) button_group.addButton(self.partidas_radio_button) (self.min_date_picker, min_date_label) = create_date_picker('À Partir de:', self) (self.max_date_picker, max_date_label) = create_date_picker('Até:', self) self.min_date_picker.dateChanged.connect( self.max_date_picker.setMinimumDate) colecao_radio_button.toggled.connect(self.min_date_picker.setDisabled) colecao_radio_button.toggled.connect(self.max_date_picker.setDisabled) self.map_users_button = QPushButton( 'Ver mapa de usuarios BGG -> Ludopedia', self) self.map_users_button.setEnabled(False) self.map_users_button.clicked.connect(self.user_map) colecao_radio_button.toggled.connect(self.map_users_button.setDisabled) group_box = QGroupBox('Dados') grid_layout = QGridLayout(group_box) grid_layout.addWidget(colecao_radio_button, 1, 1) grid_layout.addWidget(self.partidas_radio_button, 1, 2) grid_layout.addWidget(min_date_label, 2, 1) grid_layout.addWidget(self.min_date_picker, 2, 2) grid_layout.addWidget(max_date_label, 3, 1) grid_layout.addWidget(self.max_date_picker, 3, 2) grid_layout.addWidget(self.map_users_button, 4, 1, 1, 2) group_box.setLayout(grid_layout) return group_box
class Ex(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): col = QColor(0, 0, 0) self.btn = QPushButton("Dialog", self) self.btn.move(20, 20) self.btn.clicked.connect(self.showDialog) self.frm = QFrame(self) self.frm.setStyleSheet("QWidget {background-color: %s}" % col.name()) self.frm.setGeometry(130, 22, 100, 100) self.setGeometry(300, 300, 250, 180) self.setWindowTitle("Color dialog") def showDialog(self): col = QColorDialog.getColor() if col.isValid(): self.frm.setStyleSheet("QWidget {background-color: %s}" % col.name())
def __init__(self): QPushButton.__init__(self) self.about = about.About() self.setIcon(QtGui.QIcon(assets.path('about.png'))) self.setToolTip("About") self.clicked.connect(self.about.show)
def grid_layout_creation_1(self) -> None: self.group_box_1 = QGroupBox("Files") row = -1 d = cfg.PLATFORM_SETTINGS # pprint(d) layout = QGridLayout() row += 1 layout.addWidget(QLabel(bold("preferences.ini:")), row, 0) fname = cfg.PREFERENCES_INI layout.addWidget(QLabel(fname), row, 1) btn = QPushButton("Open") btn.clicked.connect(partial(opener.open_file_with_editor, self, fname)) layout.addWidget(btn, row, 2) row += 1 layout.addWidget(QLabel(bold("categories.yaml:")), row, 0) fname = cfg.categories_file() layout.addWidget(QLabel(fname), row, 1) btn = QPushButton("Open") btn.clicked.connect(partial(opener.open_file_with_editor, self, fname)) layout.addWidget(btn, row, 2) row += 1 layout.addWidget(QLabel(bold("settings.json:")), row, 0) fname = cfg.SETTINGS_FILE layout.addWidget(QLabel(fname), row, 1) btn = QPushButton("Open") btn.clicked.connect(partial(opener.open_file_with_editor, self, fname)) layout.addWidget(btn, row, 2) self.group_box_1.setLayout(layout)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.completer = None self.p_selected_id = 0 self.layout = QHBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.name = QLineEdit() self.name.setText("") self.layout.addWidget(self.name) self.details = QLabel() self.details.setText("") self.details.setVisible(False) self.layout.addWidget(self.details) self.button = QPushButton("...") self.button.setFixedWidth( self.button.fontMetrics().horizontalAdvance("XXXX")) self.layout.addWidget(self.button) self.setLayout(self.layout) self.setFocusProxy(self.name) self.button.clicked.connect(self.on_button_clicked) if self.details_field: self.name.setFixedWidth( self.name.fontMetrics().horizontalAdvance("X") * 15) self.details.setVisible(True) self.completer = QCompleter(self.dialog.model.completion_model) self.completer.setCompletionColumn( self.dialog.model.completion_model.fieldIndex(self.selector_field)) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.name.setCompleter(self.completer) self.completer.activated[QModelIndex].connect(self.on_completion)
def __init__(self, parent=None): super().__init__(parent=parent) layout = QtWidgets.QVBoxLayout(self) label1 = QLabel('입력', self) label1.setAlignment(Qt.AlignVCenter) label1.move(200, 30) label2 = QLabel('결과', self) label2.setAlignment(Qt.AlignVCenter) label2.move(710, 30) self.text_box1 = QTextEdit(self) self.text_box1.resize(350, 350) self.text_box1.move(50, 60) self.text_box2 = QTextBrowser(self) self.text_box2.append('') self.text_box2.setGeometry(550, 60, 350, 350) self.ok_base64 = QPushButton("OK", self) self.ok_base64.setGeometry(50, 420, 850, 45) self.ok_base64.clicked.connect(self.base64_conversion) self.back = QPushButton(self) self.back.setStyleSheet( ''' QPushButton{image:url(./img/back_img.png); border:0px;} QPushButton:hover{image:url(./img/back_img_ev_1.png); border:0px;} ''') self.back.setGeometry(0, 0, 50, 50) self.back.clicked.connect(self.change_stack1)
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 __init__(self, parent=None): QWidget.__init__(self, parent) self.model = None self.table_name = '' self.mapper = None self.modified = False self.name = "N/A" self.operation_type = None self.layout = QGridLayout(self) self.layout.setContentsMargins(2, 2, 2, 2) self.bold_font = QFont() self.bold_font.setBold(True) self.main_label = QLabel(self) self.main_label.setFont(self.bold_font) self.layout.addWidget(self.main_label, 0, 0, 1, 1, Qt.AlignLeft) self.commit_button = QPushButton(load_icon("accept.png"), '', self) self.commit_button.setToolTip(self.tr("Commit changes")) self.commit_button.setEnabled(False) self.revert_button = QPushButton(load_icon("cancel.png"), '', self) self.revert_button.setToolTip(self.tr("Cancel changes")) self.revert_button.setEnabled(False) self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
def __init__(self, fixed_dict_structure_modified_function, moving_dict_structure_modified_function): """ Initialize layout :param fixed_dict_structure_modified_function: function to call when the fixed image's rtss is modified :param moving_dict_structure_modified_function: function to call when the moving image's rtss is modified """ QtWidgets.QWidget.__init__(self) # Create the layout self.roi_transfer_option_layout = QtWidgets.QHBoxLayout() self.roi_transfer_handler = \ ROITransferOption(fixed_dict_structure_modified_function, moving_dict_structure_modified_function) # Create roi transfer option button self.roi_transfer_option_button = QPushButton() self.roi_transfer_option_button.setText("Open ROI Transfer Options") self.roi_transfer_option_button.clicked.connect( self.open_roi_transfer_option) # Set layout self.roi_transfer_option_layout\ .addWidget(self.roi_transfer_option_button) self.setLayout(self.roi_transfer_option_layout)
class MainWindow(QMainWindow): def __init__(self): super().__init__() self.n_times_clicked = 0 self.setWindowTitle("My App") self.button = QPushButton("Press Me!") self.button.clicked.connect(self.the_button_was_clicked) self.windowTitleChanged.connect(self.the_window_title_changed) # Set the central widget of the Window. self.setCentralWidget(self.button) def the_button_was_clicked(self): print("Clicked.") new_window_title = choice(window_titles) print("Setting title: %s" % new_window_title) self.setWindowTitle(new_window_title) def the_window_title_changed(self, window_title): print("Window title changed: %s" % window_title) if window_title == 'Something went wrong': self.button.setDisabled(True)
def setupUi(self, MainWindow): if not MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") MainWindow.resize(659, 477) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(u"centralwidget") self.verticalLayout = QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName(u"verticalLayout") self.verticalLayout.setContentsMargins(50, -1, 50, -1) self.pushButton = QPushButton(self.centralwidget) self.pushButton.setObjectName(u"pushButton") self.pushButton.setMinimumSize(QSize(0, 50)) font = QFont() font.setPointSize(16) self.pushButton.setFont(font) self.verticalLayout.addWidget(self.pushButton) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName(u"menubar") self.menubar.setGeometry(QRect(0, 0, 659, 27)) MainWindow.setMenuBar(self.menubar) self.statusbar = QStatusBar(MainWindow) self.statusbar.setObjectName(u"statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow)
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 load_game_list(self, game_layout: QGridLayout): while game_layout.count(): child = game_layout.takeAt(0) if child.widget(): child.widget().deleteLater() games = self.all_displays all_entries = iter_entry_points('zero_play.game_display') filtered_entries = self.filter_games(all_entries) for game_entry in filtered_entries: display_class = game_entry.load() display: GameDisplay = display_class() self.destroyed.connect(display.close) # type: ignore display.game_ended.connect(self.on_game_ended) # type: ignore games.append(display) games.sort(key=attrgetter('start_state.game_name')) column_count = math.ceil(math.sqrt(len(games))) for i, display in enumerate(games): row = i // column_count column = i % column_count game_name = display.start_state.game_name game_button = QPushButton(game_name) game_button.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) game_button.clicked.connect( partial( self.show_game, # type: ignore display)) game_layout.addWidget(game_button, row, column) self.ui.history_game.addItem(game_name, userData=display) if display.rules_path is not None: game_rules_action = self.ui.menu_rules.addAction(game_name) game_rules_action.triggered.connect( partial(self.on_rules, display))
class ProgressExample(QWidget): """The main ui components""" def __init__(self, parent=None): super(ProgressExample, self).__init__(parent) self.setupUi() def setupUi(self): self.setWindowTitle('QProgressBar Example') self.btn = QPushButton('Click Me!') self.btn.clicked.connect(self.btnFunc) self.pBar = QProgressBar() self.pBar.setValue(0) self.resize(300, 100) self.vbox = QVBoxLayout() self.vbox.addWidget(self.pBar) self.vbox.addWidget(self.btn) self.setLayout(self.vbox) self.show() def btnFunc(self): self.thread = Thread() self.thread._signal.connect(self.signal_accept) self.thread.start() self.btn.setEnabled(False) def signal_accept(self, msg): self.pBar.setValue(int(msg)) if self.pBar.value() == 99: self.pBar.setValue(0) self.btn.setEnabled(True)
def __init__(self, programInstance: ProgramInstance, uniqueRun): super().__init__() AppGlobals.Instance().onChipModified.connect(self.UpdateParameterItems) self.editingParameterVisibility = False self.programInstance = programInstance self.uniqueRun = uniqueRun self._programNameWidget = QLabel() layout = QVBoxLayout() self.setLayout(layout) self.runButton = QPushButton("Run") self.runButton.clicked.connect(self.RunProgram) self._stopButton = QPushButton("Stop") self._stopButton.clicked.connect(self.StopProgram) self.parameterItems: List[ProgramParameterItem] = [] self._parametersLayout = QVBoxLayout() layout.addWidget(self._programNameWidget) layout.addLayout(self._parametersLayout) layout.addWidget(self.runButton) layout.addWidget(self._stopButton) timer = QTimer(self) timer.timeout.connect(self.UpdateInstanceView) timer.start(30) self.UpdateInstanceView() self.UpdateParameterItems()
def initUI(self): """ Init widget """ vbox = QVBoxLayout() vbox.addSpacing(2) # Head hbox = QHBoxLayout() hbox.addSpacing(3) # 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 | QtCore.Qt.AlignTop) # Header of this widget self._headWidget = QLabel("Add new figure") hbox.addWidget(self._headWidget, 1, QtCore.Qt.AlignCenter | QtCore.Qt.AlignTop) # Create button to choose color of new figure self._pickColorButton = QPushButton('Pick color') self._pickColorButton.clicked.connect(self.update_color_name) hbox.addWidget(self._pickColorButton, 2, QtCore.Qt.AlignRight | QtCore.Qt.AlignTop) # Create button to save figure self._saveFigureButton = QPushButton('Save') self._saveFigureButton.clicked.connect(self.save_figure_shape) hbox.addWidget(self._saveFigureButton, 2, QtCore.Qt.AlignRight | QtCore.Qt.AlignTop) vbox.addLayout(hbox, 0) grid = QGridLayout() self._sheet = [] self._choosenFigureList = [] self._proposedFiguresList = [] self._savedColor = 'black' for i in range(self.MAX_X): row = [] for j in range(self.MAX_Y): single = DrawBlockQFrame(self.signalPressedFrames, j, i) if i == 3 and j == 3: # Button in the center - must be with blur color # Save figure - possible only if blue button also clicked # This magic stuff are made in order to simplify saving figure single.COLOR_DEFAULT = 'blue' single.default_color() self.centerSheet = single row.append(single) grid.addWidget(single, i, j) self._sheet.append(row) vbox.addLayout(grid, 1) self.setLayout(vbox) self.setWindowTitle("Add new figure")
class Window(QMainWindow): def __init__(self, parent=None): super().__init__(parent) self.clicksCount = 0 self.setupUi() def setupUi(self): self.setWindowTitle("Freezing GUI") self.resize(300, 150) self.centralWidget = QWidget() self.setCentralWidget(self.centralWidget) # Create and connect widgets self.clicksLabel = QLabel("Counting: 0 clicks", self) self.clicksLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.stepLabel = QLabel("Long-Running Step: 0") self.stepLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.countBtn = QPushButton("Click me!", self) self.countBtn.clicked.connect(self.countClicks) self.longRunningBtn = QPushButton("Long-Running Task!", self) self.longRunningBtn.clicked.connect(self.runLongTask) # Set the layout layout = QVBoxLayout() layout.addWidget(self.clicksLabel) layout.addWidget(self.countBtn) layout.addStretch() layout.addWidget(self.stepLabel) layout.addWidget(self.longRunningBtn) self.centralWidget.setLayout(layout) def countClicks(self): self.clicksCount += 1 self.clicksLabel.setText(f"Counting: {self.clicksCount} clicks") def reportProgress(self, n): self.stepLabel.setText(f"Long-Running Step: {n}") def runLongTask(self): # 创建 QThread self.thread = QThread() # 创建 worker 对象 self.worker = Worker() # 将 work 移到 thread self.worker.moveToThread(self.thread) # 连接信号和槽 self.thread.started.connect(self.worker.run) self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.thread.finished.connect(self.thread.deleteLater) self.worker.progress.connect(self.reportProgress) # 启动线程 self.thread.start() # 结束 self.longRunningBtn.setEnabled(False) self.thread.finished.connect( lambda: self.longRunningBtn.setEnabled(True)) self.thread.finished.connect( lambda: self.stepLabel.setText("Long-Running Step: 0"))
def __init__(self, is_visible): QPushButton.__init__(self) self.setIcon(QtGui.QIcon(assets.path('close.png'))) self.setToolTip("Close") self.clicked.connect(self.close) if not is_visible: self.hide()
def _show_pickup_spoiler(button: QtWidgets.QPushButton): target_player = getattr(button, "target_player", None) if target_player is not None: label = f"{button.item_name} for {button.player_names[target_player]}" else: label = button.item_name button.setText(label) button.item_is_hidden = False
def __init__(self): QPushButton.__init__(self) self.stat_type: str = StatsType.ZONE self.setIcon(QtGui.QIcon(assets.path('reset.png'))) self.setToolTip("Reset") self.clicked.connect(self.reset)
def initUI(self): """ Init app """ vbox = QVBoxLayout() # Label with name of the game (i.e. TetrisView in our case) self._label_widget = DanceText("Tetris", self) #self._label_widget.setMaximumHeight(50) self._label_widget.setFrameStyle(QFrame.Panel) self._label_widget.setStyleSheet( "background-color: rgb(200, 160, 160)") vbox.addWidget(self._label_widget) # Create button and widget for game self._game_button = QPushButton("Play game") pal = self._game_button.palette() pal.setColor(QPalette.Button, QColor(Qt.green)) self._game_button.setAutoFillBackground(True) self._game_button.setPalette(pal) vbox.addWidget(self._game_button) # Create button and widget for settings self._settings_button = QPushButton("Settings") pal = self._settings_button.palette() pal.setColor(QPalette.Button, QColor(Qt.blue)) self._settings_button.setAutoFillBackground(True) self._settings_button.setPalette(pal) vbox.addWidget(self._settings_button) self._add_custom_figure_button = QPushButton("Add new figure") pal = self._add_custom_figure_button.palette() pal.setColor(QPalette.Button, QColor(Qt.green)) self._add_custom_figure_button.setAutoFillBackground(True) self._add_custom_figure_button.setPalette(pal) vbox.addWidget(self._add_custom_figure_button) # Create button and widget about_game self._about_game_button = QPushButton("About game") pal = self._about_game_button.palette() pal.setColor(QPalette.Button, QColor(Qt.yellow)) self._about_game_button.setAutoFillBackground(True) self._about_game_button.setPalette(pal) vbox.addWidget(self._about_game_button) # Create quit button self._exit_button = QPushButton("Exit") pal = self._exit_button.palette() pal.setColor(QPalette.Button, QColor(Qt.red)) self._exit_button.setAutoFillBackground(True) self._exit_button.setPalette(pal) self._exit_button.clicked.connect(QApplication.quit) vbox.addWidget(self._exit_button) self.setLayout(vbox) self.setWindowTitle("Main menu")
def __init__(self, parent=None): super(BlockingClient, self).__init__(parent) self.thread = FortuneThread() self.currentFortune = '' hostLabel = QLabel("&Server name:") portLabel = QLabel("S&erver port:") for ipAddress in QNetworkInterface.allAddresses(): if ipAddress != QHostAddress.LocalHost and ipAddress.toIPv4Address( ) != 0: break else: ipAddress = QHostAddress(QHostAddress.LocalHost) ipAddress = ipAddress.toString() self.hostLineEdit = QLineEdit(ipAddress) self.portLineEdit = QLineEdit() self.portLineEdit.setValidator(QIntValidator(1, 65535, self)) hostLabel.setBuddy(self.hostLineEdit) portLabel.setBuddy(self.portLineEdit) self.statusLabel = QLabel( "This example requires that you run the Fortune Server example as well." ) self.statusLabel.setWordWrap(True) self.getFortuneButton = QPushButton("Get Fortune") self.getFortuneButton.setDefault(True) self.getFortuneButton.setEnabled(False) quitButton = QPushButton("Quit") buttonBox = QDialogButtonBox() buttonBox.addButton(self.getFortuneButton, QDialogButtonBox.ActionRole) buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole) self.getFortuneButton.clicked.connect(self.requestNewFortune) quitButton.clicked.connect(self.close) self.hostLineEdit.textChanged.connect(self.enableGetFortuneButton) self.portLineEdit.textChanged.connect(self.enableGetFortuneButton) self.thread.newFortune.connect(self.showFortune) self.thread.error.connect(self.displayError) mainLayout = QGridLayout() mainLayout.addWidget(hostLabel, 0, 0) mainLayout.addWidget(self.hostLineEdit, 0, 1) mainLayout.addWidget(portLabel, 1, 0) mainLayout.addWidget(self.portLineEdit, 1, 1) mainLayout.addWidget(self.statusLabel, 2, 0, 1, 2) mainLayout.addWidget(buttonBox, 3, 0, 1, 2) self.setLayout(mainLayout) self.setWindowTitle("Blocking Fortune Client") self.portLineEdit.setFocus()
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)