def setUpMainWindow(self): """Set up the GUI's main window.""" search_line_edit = QLineEdit() search_line_edit.setPlaceholderText( "Enter text to search for a word below") list_of_words = self.loadWordsFromFile() list_view = QListView() # Create a model instance and pass the list of words to the model model = ListModel(list_view, list_of_words) list_view.setModel(model) # Create QCompleter object that shares the same model as the QListView completer = QCompleter(list_of_words) completer.setFilterMode(Qt.MatchFlag.MatchStartsWith) completer.setModel(model) search_line_edit.setCompleter( completer) # Set the completer for the QLineEdit # Create a layout and organize all of the objects # into a QGroupBox main_v_box = QVBoxLayout() main_v_box.addWidget(search_line_edit) main_v_box.addWidget(list_view) word_group_box = QGroupBox("Keywords") word_group_box.setLayout(main_v_box) self.setCentralWidget(word_group_box)
def __init__( self, icon: QStyle.StandardPixmap, labelText: str, parent: Optional[QWidget] = None, *args: Tuple[Any, Any], **kwargs: Tuple[Any, Any], ) -> None: """ An icon button with a text label. """ super(LabelledIconButton, self).__init__(parent=parent, *args, **kwargs) self.setContentsMargins(0, 0, 0, 0) verticalLayout = QVBoxLayout(self) verticalLayout.setContentsMargins(0, 0, 0, 0) button = QToolButton(self) button.setIcon(self.style().standardIcon(icon), ) # connect the button to the onButtonPressed signal self.onButtonPressed = button.clicked label = QLabel(labelText, self) verticalLayout.addWidget(button) verticalLayout.addWidget(label) verticalLayout.setAlignment(label, Qt.Alignment.AlignHCenter) verticalLayout.setAlignment(button, Qt.Alignment.AlignHCenter) self.setLayout(verticalLayout)
def __init__( self, onLoadLastMazePressed: Callable[[], None], onMazeLoadedFromPath: Callable[[str], None], onMazeSpecificationChosen: Callable[[MazeGenerationSpecification], None], parent: Optional[QWidget] = None, *args: Tuple[Any, Any], **kwargs: Tuple[Any, Any], ) -> None: """ The view used for prompting the user to load, generate or load last maze. """ super(MazeLoaderView, self).__init__(parent=parent, *args, **kwargs) self.setContentsMargins(0, 0, 0, 0) self.setWindowTitle("Load a Maze") self.__onLoadLastMazeChosen = onLoadLastMazePressed self.__onMazeFilePathChosen = onMazeLoadedFromPath self.__onMazeSpecificationChosen = onMazeSpecificationChosen # create layout layout = QVBoxLayout() # add all the buttons to the layout for button in self.__getButtons(): layout.addWidget(button) self.setLayout(layout)
def startGUI(): app = QApplication([]) app.setStyle('Fusion') if opts.timeclockOpts["darkTheme"]: pass window = QWidget() window.setWindowTitle(opts.timeclockOpts["title"]) window.setWindowIcon( QtGui.QIcon("../data/assets/" + opts.timeclockOpts["logo"])) mainLayout = QVBoxLayout() mainLayout.setSpacing(20) mainLayout.addLayout(makeTitle()) global tabsObject tabsObject = makeNameArea() mainLayout.addWidget(tabsObject) updateNamesTable() mainLayout.addLayout(makeActions(app)) window.setLayout(mainLayout) window.show() print("1024 x 768") print(window.width(), " x ", window.height()) print("", 1024 - window.width(), "\t", 768 - window.height()) app.exec()
def __init__(self): super().__init__() self.setWindowTitle("File Hash Checker") self.setGeometry(0, 0, 600, 300) self.labelFileDropper = FileDropper("Datei auswählen") #self.selectFileButton.clicked.connect(self.get_file_to_check) self.labelFileDropper.setAcceptDrops(True) self.labelFileDropper.setStyleSheet( "border: 1px solid black; border-radius: 15px; text-align: center; " "height: 200px") self.labelFileDropper.move(0, 0) self.labelFileDropper.resize(500, 150) self.labelMD5Hash = QLabel( "Bitte zu vergleichenden MD5 Hash eingeben:") self.textMD5Hash = QLineEdit() self.buttonCompareMD5 = QPushButton('MD5 Vergleichen') self.buttonCompareMD5.clicked.connect(self.compare_md5) self.labelIsSame = QLabel() layout = QVBoxLayout() layout.addWidget(self.labelFileDropper) layout.addWidget(self.labelMD5Hash) layout.addWidget(self.textMD5Hash) layout.addWidget(self.buttonCompareMD5) layout.addWidget(self.labelIsSame) self.setLayout(layout)
def initUI(self): self.setWindowTitle("查看回收站文件夹内容") self.form = QVBoxLayout() for item in iter(self.files): ico = QPushButton(set_file_icon(item.name), item.name) ico.setStyleSheet( "QPushButton {border:none; background:transparent; color:black;}" ) ico.adjustSize() it = QLabel(f"<font color='#CCCCCC'>({item.size})</font>") hbox = QHBoxLayout() hbox.addWidget(ico) hbox.addStretch(1) hbox.addWidget(it) self.form.addLayout(hbox) self.form.setSpacing(10) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons( QDialogButtonBox.StandardButton.Close) self.buttonBox.button( QDialogButtonBox.StandardButton.Close).setText("关闭") self.buttonBox.setStyleSheet(btn_style) self.buttonBox.rejected.connect(self.reject) vbox = QVBoxLayout() vbox.addLayout(self.form) vbox.addStretch(1) vbox.addWidget(self.buttonBox) self.setLayout(vbox)
class Window(QMainWindow): def __init__(self): super().__init__() self.width = 150 self.height = 150 self.xPos = 600 self.yPos = 400 self.initUI() def initUI(self): self.setGeometry(self.xPos, self.yPos, self.width, self.height) self.vBoxLayout = QVBoxLayout() self.canvas = Canvas(width=150, height=150, penColor=(21, 21, 21), canvasColor=(245, 177, 66), strokeWidth=5, borderWidth=2, borderColor=(21, 21, 21)) self.vBoxLayout.addWidget(self.canvas, alignment=Qt.AlignmentFlag.AlignCenter) self.centralWidget = QWidget(self) self.centralWidget.setLayout(self.vBoxLayout) self.setCentralWidget(self.centralWidget) self.show()
class App(QDialog): def __init__(self): app = QApplication(sys.argv) super().__init__() self.setWindowTitle('PyQt6 Grid Layout') self.setGeometry(100, 100, 320, 100) self.CreateGridLayout() self.windowLayout = QVBoxLayout() self.windowLayout.addWidget(self.horizontalGroupBox) self.setLayout(self.windowLayout) self.show() sys.exit(app.exec()) def CreateGridLayout(self): self.horizontalGroupBox = QGroupBox("Grid") self.layout = QGridLayout() self.layout.setColumnStretch(2, 4) self.layout.setColumnStretch(1, 4) for label in "123456789": self.MakeButton(label) self.horizontalGroupBox.setLayout(self.layout) def MakeButton(self, label): button = QPushButton(label) button.clicked.connect(lambda: self.on_click(button)) self.layout.addWidget(button) def on_click(self, pushButton): print('PyQt5 {0} button clicked.'.format(pushButton.text()))
def setActionsBox(self, TrainPanel): hLayout = QVBoxLayout() hLayout.addWidget(self.calibrateButton) hLayout.addWidget(self.sessionButton) hLayout.setAlignment(self.calibrateButton, Qt.Alignment.AlignCenter) hLayout.setAlignment(self.sessionButton, Qt.Alignment.AlignCenter) self.box2.setLayout(hLayout)
def __init__( self, parent: Optional[QWidget] = None, *args: Tuple[Any, Any], **kwargs: Tuple[Any, Any], ) -> None: """ The log layout consisting of, for each command: Left: Command name Right: Command result """ super(VerticalLogLayout, self).__init__(parent=parent, *args, **kwargs) # set layout and add placeholder layouts to ensure they aren't automatically destroyed later layout = QHBoxLayout() self.__commandNames.append("Command name") self.__commandResults.append("Result") commandNamesBox = QVBoxLayout() commandResultsBox = QVBoxLayout() # add the human descriptions text to the layouts for i in range(0, len(self.__commandNames)): commandNamesBox.addWidget(QLabel(self.__commandNames[i])) commandResultsBox.addWidget(QLabel(self.__commandResults[i])) layout.addLayout(commandNamesBox) layout.addLayout(commandResultsBox) # remember to set the layout! self.setLayout(layout)
class AddDialog(QDialog): """Add Contact dialog.""" def __init__(self, parent=None): """Initializer""" super().__init__(parent=parent) self.setWindowTitle("Add Contact") self.layout = QVBoxLayout() self.setLayout(self.layout) self.data = None self.setupUI() def setupUI(self): """Setup the Add Contact dialog's GUI.""" # Create line edits for data fields self.nameField = QLineEdit() self.nameField.setObjectName("Name") self.jobField = QLineEdit() self.jobField.setObjectName("Job") self.emailField = QLineEdit() self.emailField.setObjectName("Email") # Lay out the data fields layout = QFormLayout() layout.addrow("Name:", self.nameField) layout.addrow("Job:", self.jobField) layout.addrow("Email:", self.emailField) self.layout.addLayout(layout) # add standard buttons to the dialog and conntect them self.buttonsBox = QDialogButtonBox(self) self.buttonsBox.setOrientation(Qt.Horizontal) self.buttonsBox.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) self.buttonsBox.accepted.connect(self.accept) self.buttonsBox.rejected.connect(self.reject) self.layout.addWidget(self.buttonsBox) def accept(self): """Accept the data provided through the dialog.""" self.data = [] for field in (self.nameField, self.jobField, self.emailField): if not field.text(): QMessageBox.critical( self, "Error!", f"You must provide a contact's{field.objectName()}", ) self.data = None # reset .data return self.data.append(field.text()) if not self.data: return() super().accept()
def InitWindow(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.createCheckBox() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) vbox.addWidget(self.label) self.setLayout(vbox) self.show()
class MainWidget(QWidget): def __init__(self): super(MainWidget, self).__init__() self.resize(500, 600) self.setWindowTitle("喜马拉雅下载 by[Zero] " + __VERSION__) self.mainlayout = QVBoxLayout() self.setLayout(self.mainlayout) self.groupbox = QGroupBox("选择类型") self.groupbox.setFixedHeight(50) hlayout = QHBoxLayout(self.groupbox) self.signal_m4a = QRadioButton("单个下载") self.mut_m4a = QRadioButton("专辑下载") self.vip_signal_m4a = QRadioButton("VIP单个下载") self.vip_m4a = QRadioButton("VIP专辑下载") hlayout.addWidget(self.signal_m4a) hlayout.addWidget(self.mut_m4a) hlayout.addWidget(self.vip_signal_m4a) hlayout.addWidget(self.vip_m4a) self.mainlayout.addWidget(self.groupbox) frame01 = QFrame(self) child_layout = QVBoxLayout() print(self.width()) label01 = QLabel("链 接", self) label02 = QLabel("下载目录", self) self.url_lineedit = QLineEdit(self) self.dir_lineedit = QLineEdit(self) hlayout01 = QHBoxLayout() hlayout01.addWidget(label01, 1) hlayout01.addWidget(self.url_lineedit, 9) hlayout02 = QHBoxLayout() hlayout02.addWidget(label02, 1) hlayout02.addWidget(self.dir_lineedit, 9) child_layout.addLayout(hlayout01) child_layout.addLayout(hlayout02) child_layout.setContentsMargins( 5, 0, 5, 0) #(int left, int top, int right, int bottom) frame01.setLayout(child_layout) self.download_progressbar = QProgressBar() self.download_progressbar.setAlignment( QtCore.Qt.Alignment.AlignCenter) #文字居中 self.download_progressbar.setValue(88) self.download_btn = QPushButton("开始下载") self.show_plaintextedit = QPlainTextEdit() self.show_plaintextedit.setMinimumHeight(400) self.mainlayout.addWidget(frame01) self.mainlayout.addWidget(self.download_progressbar) self.mainlayout.addWidget(self.download_btn) self.mainlayout.addWidget(self.show_plaintextedit) self.mainlayout.addStretch() ### 设置stylesheet self.download_btn.setStyleSheet( 'QPushButton:pressed{ text-align: center;background-color:red;}')
def InitWindow(self): self.setWindowIcon(QtGui.QIcon("home.png")) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.createLayout() vbox = QVBoxLayout() vbox.addWidget(self.groupBox) self.setLayout(vbox) self.show()
def __init__(self): app = QApplication(sys.argv) super().__init__() self.setWindowTitle('PyQt6 Horizontal Layout') self.setGeometry(100, 100, 400, 100) self.CreateHorizontalLayout() windowLayout = QVBoxLayout() windowLayout.addWidget(self.horizontalGroupBox) self.setLayout(windowLayout) self.show() sys.exit(app.exec())
def show_setting(self, conf: dict, layout: QGridLayout): groups = list() x = 0 y = 0 shape = 3 for key in conf.keys(): if type(conf[key]) == bool or type(conf[key]) == str: continue conf_title = conf[key]["title"] conf_enabled = conf[key]["enabled"] conf_times = conf[key]["times"] group = QGroupBox(conf_title) group.setStyleSheet("QGroupBox{border-radius:5px;}") group.setToolTip(conf_title + " 的设置") enabled = QCheckBox("启用") enabled.setObjectName(key) enabled.setToolTip("单击切换开关状态") enabled.setChecked(conf_enabled) enabled.setStyleSheet( "QCheckBox::indicator{width:10px;height:10px;border:none;border-radius:5px;background:#9BE3DE;}QCheckBox::indicator:unchecked{background:#BEEBE9;}QCheckBox::indicator:unchecked:hover{background:#9AD3BC;}QCheckBox::indicator:checked{background:#95E1D3;}QCheckBox::indicator:checked:hover{background:#98DED9;}" ) times = QHBoxLayout() times_label = QLabel("次数:") times_label.setStyleSheet( "QLabel{background:transparent;border:none;border-radius:5px;}" ) times_input = EnhancedEdit() times_input.setObjectName(key) times_input.setText(str(conf_times)) times_input.setToolTip("仅限正整数") times_input.setValidator( QRegularExpressionValidator( QRegularExpression("^[1-9][0-9]{1,8}$"))) times_input.setStyleSheet( "QLineEdit{border:1px solid #F3EAC2;border-radius:5px;background:transparent;}QLineEdit:hover{border:1px solid #F5B461;}" ) times.addWidget(times_label) times.addWidget(times_input) group_layout = QVBoxLayout() group_layout.addWidget(enabled) group_layout.addLayout(times) group.setLayout(group_layout) group.setObjectName(key) groups.append(group) for group in groups: if y >= shape: x = x + 1 y = 0 layout.addWidget(group, x, y) y = y + 1 self.logger.debug("最后的元素位置:(%d,%d)" % (x, y)) return (x, y)
class MainWindowContentSection(QWidget): def __init__(self, main_window_content, sub_header_text): super(MainWindowContentSection, self).__init__() self.main_window_content = main_window_content self.layout = QVBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setAlignment(Qt.AlignmentFlag.AlignTop) self.layout.setSpacing(10) self.sub_header = QLabel(sub_header_text) self.sub_header.setFont(SUBHEADER_FONT) self.layout.addWidget(self.sub_header)
def setUpMainWindow(self): """Set up the GUI's main window.""" header_label = QLabel("List of Users") # Create model and table objects model = QStandardItemModel() model.setColumnCount(3) model.setHorizontalHeaderLabels(["Name", "Birthdate", "Actions"]) table_view = QTableView() table_view.setEditTriggers( QAbstractItemView.EditTrigger.NoEditTriggers) # NOTE: Uncomment for table cells to be unselectable #table_view.setSelectionMode(QAbstractItemView.SelectionMode.NoSelection) table_view.setModel(model) table_view.horizontalHeader().setSectionResizeMode( 0, QHeaderView.ResizeMode.Stretch) names_list = ["Willman, Joshua", "Davis, Scott", "Garcia, Sky"] # Add items to each row in the table by looping over # the names_list and adding the date edit and button widgets for row, name in enumerate(names_list): model.setItem(row, QStandardItem(name)) # Setting the widget at an index in a QTableView involves # acquiring the QModelIndex values of the current position. # One way to do this is to use the QAbstractItemModel.sibling() # method to retrieve the QModelIndex index from the specified # row and column (here the column is 1) index = table_view.model().sibling(row, 1, QModelIndex()) date_edit = QDateEdit(QDate.currentDate( )) # Create QDateEdit object that starts at current date date_edit.setDateRange(QDate(1900, 1, 1), QDate.currentDate()) date_edit.setDisplayFormat("MM/dd/yyyy") date_edit.setAlignment( Qt.AlignmentFlag.AlignRight) # Align the text date_edit.setAutoFillBackground(True) table_view.setIndexWidget(index, date_edit) # Set the widgets in the final column for each row index = table_view.model().sibling(row, 2, QModelIndex()) table_view.setIndexWidget(index, EditCellWidget(table_view)) # Set up main layout and container object for main window main_v_box = QVBoxLayout() main_v_box.addWidget(header_label) main_v_box.addWidget(table_view) container = QWidget() container.setLayout(main_v_box) self.setCentralWidget(container)
def InitWindow(self): self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) vbox = QVBoxLayout() labelImage = QLabel(self) pixmap = QPixmap("resources/pyqt5_image_window-300x180.png") labelImage.setPixmap(pixmap) vbox.addWidget(labelImage) self.setLayout(vbox) self.show()
def __init__(self, parent, directory, is_checked): """Simple modal Preferences dialog""" super().__init__(parent) self.setWindowTitle("Preferences") self.setModal(True) image_dir_label = QLabel( f"<b>Images Location:</b> {directory.absolutePath()}") self.delete_images_checkbox = QCheckBox("Delete Original Images") self.delete_images_checkbox.setToolTip( """<p>If checked, images that are copied to the <b>Images Location</b> are also deleted from their original location.</p>""" ) self.delete_images_checkbox.setChecked(is_checked) handling_v_box = QVBoxLayout() handling_v_box.addWidget(self.delete_images_checkbox) handling_group_box = QGroupBox("Image Handling:") handling_group_box.setLayout(handling_v_box) self.button_box = QDialogButtonBox( QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel) self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.reject) # Add a layout to the dialog box dialog_v_box = QVBoxLayout() dialog_v_box.addWidget(image_dir_label) dialog_v_box.addWidget(handling_group_box) dialog_v_box.addStretch(1) dialog_v_box.addWidget(self.button_box) self.setLayout(dialog_v_box)
class NuggetListWidget(QWidget): def __init__(self, interactive_matching_widget): super(NuggetListWidget, self).__init__(interactive_matching_widget) self.interactive_matching_widget = interactive_matching_widget self.layout = QVBoxLayout(self) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(10) # top widget self.top_widget = QWidget() self.top_layout = QHBoxLayout(self.top_widget) self.top_layout.setContentsMargins(0, 0, 0, 0) self.top_layout.setSpacing(10) self.layout.addWidget(self.top_widget) self.description = QLabel( "Below you see a list of guessed matches for you to confirm or correct." ) self.description.setFont(LABEL_FONT) self.top_layout.addWidget(self.description) self.stop_button = QPushButton("Continue With Next Attribute") self.stop_button.setFont(BUTTON_FONT) self.stop_button.clicked.connect(self._stop_button_clicked) self.stop_button.setMaximumWidth(240) self.top_layout.addWidget(self.stop_button) # nugget list self.nugget_list = CustomScrollableList(self, NuggetListItemWidget) self.layout.addWidget(self.nugget_list) def update_nuggets(self, nuggets): max_start_chars = max([ nugget[CachedContextSentenceSignal]["start_char"] for nugget in nuggets ]) self.nugget_list.update_item_list(nuggets, max_start_chars) def _stop_button_clicked(self): self.interactive_matching_widget.main_window.give_feedback_task( {"message": "stop-interactive-matching"}) def enable_input(self): self.stop_button.setEnabled(True) self.nugget_list.enable_input() def disable_input(self): self.stop_button.setDisabled(True) self.nugget_list.disable_input()
def initUI(self): lcd = QLCDNumber(self) sld = QSlider(Qt.Orientation.Horizontal, self) vbox = QVBoxLayout() vbox.addWidget(lcd) vbox.addWidget(sld) self.setLayout(vbox) sld.valueChanged.connect(lcd.display) self.setGeometry(300, 300, 350, 250) self.setWindowTitle('Signal and slot') self.show()
def __init__( self, parent=None, ): super(AllKeysDialog, self).__init__(parent) layout = QVBoxLayout(self) label = QLabel("Below you can see a list with all the supported keys.") self.list = QListWidget() self.listAllKeys() layout.addWidget(label) layout.setAlignment(label, Qt.Alignment.AlignTop) layout.addWidget(self.list) self.setLayout(layout) self.window().setMaximumWidth(300)
class StatsFrame(QWidget): """Calculate statistics for each turn of the players.""" label_ssheet = """QLabel { font-size: 15pt; font-weight: bold; padding-right: 5px; color: #fca018;}""" def __init__(self, parent=None, window=None): super().__init__(parent=parent) self.window = window self.hlayout = QHBoxLayout() self.setLayout(self.hlayout) self.vbox1 = QVBoxLayout() self.vbox2 = QVBoxLayout() self.cardCount = HLabels("Cards in Deck: ", "0") self.deckCount = HLabels("Number of Decks: ", "0") self.playerCount = HLabels("Number of Players: ", "0") self.breaking21 = HLabels("Breaking 21: ", " 0") self.exactly = HLabels("Exactly 21: ", " 0") self.under21 = HLabels("Under 21: ", " 0") self.probabilities = QLabel("Probabilities", parent=self) self.quantities = QLabel("Quantities", parent=self) self.vbox2.addWidget(self.quantities) self.vbox2.addLayout(self.cardCount) self.vbox2.addLayout(self.deckCount) self.vbox2.addLayout(self.playerCount) self.vbox1.addWidget(self.probabilities) self.vbox1.addLayout(self.breaking21) self.vbox1.addLayout(self.exactly) self.vbox1.addLayout(self.under21) self.hlayout.addLayout(self.vbox1) self.hlayout.addLayout(self.vbox2) self.quantities.setStyleSheet(self.label_ssheet) self.probabilities.setStyleSheet(self.label_ssheet) self.probabilities.setAlignment(Qt.AlignmentFlag(4)) self.quantities.setAlignment(Qt.AlignmentFlag(4)) self.labels = { "cards": self.cardCount, "decks": self.deckCount, "players": self.playerCount, "breaking": self.breaking21, "exactly": self.exactly, "under": self.under21, } self.window.driver.hook(self.labels)
def __init__(self): app = QApplication(sys.argv) super().__init__() self.setWindowTitle('Generic Configuration Tool') self.setGeometry(100, 100, 640, 480) self.isEdited = False self.saveAndClose = SaveAndCloseActions(self) centralWidget = QWidget() vbox = QVBoxLayout() centralWidget.setLayout(vbox) vbox.addWidget(TabContainer(self)) vbox.addStretch(1) vbox.addWidget(self.saveAndClose) self.setCentralWidget(centralWidget) self.show() sys.exit(app.exec())
def InitWindow(self): self.setWindowIcon(QtGui.QIcon(self.iconName)) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) vbox = QVBoxLayout() label = QLabel("This is PyQt6 Label") vbox.addWidget(label) label2 = QLabel("This is PyQt6 GUI Application Development") label2.setFont(QtGui.QFont("Sanserif ", 20)) label2.setStyleSheet('color:red') vbox.addWidget(label2) self.setLayout(vbox) self.show()
def __init__(self): super().__init__() self.logger=logging.getLogger() handler=QLogger(parent=self,update_log_text_signal=self.update_log_text_signal) self.update_log_text_signal.connect(handler.widget.appendPlainText) handler.widget.textChanged.connect(handler.scroll_widget_to_bottom) self.logger.setLevel(logging.INFO) # Here set the log level you want handler.setFormatter(logging.Formatter(fmt="%(asctime)s-%(levelname)s-%(message)s",datefmt="%Y-%m-%d %H:%M:%S")) self.logger.addHandler(handler) button=QPushButton("&Test") button.clicked.connect(self.button_handler) button.setDefault(True) layout_=QVBoxLayout() layout_.addWidget(handler.widget) layout_.addWidget(button) self.setLayout(layout_)
def initUI(self): self.setWindowTitle("合并文件") self.setWindowIcon(QIcon(SRC_DIR + "upload.ico")) self.logo = QLabel() self.logo.setPixmap(QPixmap(SRC_DIR + "logo3.gif")) self.logo.setStyleSheet("background-color:rgb(0,153,255);") self.logo.setAlignment(Qt.AlignmentFlag.AlignCenter) # lable self.choose_lb = QLabel("选择文件夹") # folder self.choose_folder = MyLineEdit(self) self.choose_folder.setObjectName("choose_folder") self.choose_folder.clicked.connect(self.slot_choose_folder) self.status = QLabel(self) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText("提取") self.buttonBox.button( QDialogButtonBox.StandardButton.Cancel).setText("关闭") self.buttonBox.setStyleSheet(btn_style) vbox = QVBoxLayout() hbox_head = QHBoxLayout() hbox_button = QHBoxLayout() hbox_head.addWidget(self.choose_lb) hbox_head.addWidget(self.choose_folder) hbox_button.addWidget(self.buttonBox) vbox.addWidget(self.logo) vbox.addStretch(1) vbox.addWidget(self.status) vbox.addLayout(hbox_head) vbox.addStretch(1) vbox.addLayout(hbox_button) self.setLayout(vbox) self.setMinimumWidth(350) # 设置信号 self.buttonBox.accepted.connect(self.slot_btn_ok) self.buttonBox.rejected.connect(self.slot_btn_no) self.buttonBox.rejected.connect(self.reject)
def __init__( self, onValueChanged: Callable[[int], None], parent: Optional[QWidget] = None, *args: Tuple[Any, Any], **kwargs: Tuple[Any, Any], ) -> None: """ Slow/fast slider for maze solver agents speed """ super(MazeSolverSpeedControlView, self).__init__(parent=parent, *args, **kwargs) self.setContentsMargins(0, 0, 0, 0) layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) slider = QSlider(Qt.Orientations.Horizontal) # minimum of 1 op/s (0 would result in a divide by zero op and thus crash) slider.setMinimum(1) # maximum of 50 op/s slider.setMaximum(70) # initial value in the middle slider.setValue(35) # connect the onValueChange event to the method passed to this widget slider.valueChanged.connect(onValueChanged) # type: ignore # slow/fast horizontal labels view slowFastLabelsLayout = QHBoxLayout() slowFastLabelsLayout.setContentsMargins(0, 0, 0, 0) slowLabel = QLabel("Slow") fastLabel = QLabel("Fast") slowFastLabelsLayout.addWidget(slowLabel) slowFastLabelsLayout.addStretch() slowFastLabelsLayout.addWidget(fastLabel) layout.addWidget(slider) layout.addLayout(slowFastLabelsLayout) self.setLayout(layout)
def setUpMainWindow(self): """Set up the GUI's main window.""" header_label = QLabel("List of Users") # Create model and table objects model = QStandardItemModel() model.setColumnCount(3) model.setHorizontalHeaderLabels(["Name", "Birthdate", "Actions"]) table_view = QTableView() # NOTE: setEditTriggers() is not used so that the user # can double-click and edit cells table_view.setModel(model) table_view.horizontalHeader().setSectionResizeMode( 0, QHeaderView.ResizeMode.Stretch) # Set the item delegate for a specific column, in this case column 1 table_view.setItemDelegateForColumn(1, DateEditDelegate()) names_list = ["Willman, Joshua", "Davis, Scott", "Garcia, Sky"] # Add items to each row in the table by looping over # the names_list and adding the date edit and button widgets for row, name in enumerate(names_list): model.setItem(row, QStandardItem(name)) # Create an item and set the initial value for the second column. # Here the QDate values are converted to strings to make it easier # to align the text without having to subclass a model class date_item = QStandardItem( QDate.currentDate().toString("MM/dd/yyyy")) date_item.setTextAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight) model.setItem(row, 1, date_item) # Set the widgets in the final column for each row index = model.index(row, 2, QModelIndex()) table_view.setIndexWidget(index, EditCellWidget(table_view)) # Set up main layout and container object for main window main_v_box = QVBoxLayout() main_v_box.addWidget(header_label) main_v_box.addWidget(table_view) container = QWidget() container.setLayout(main_v_box) self.setCentralWidget(container)