def __init__(self): super().__init__() StylesheetLoader.RegisterWidget(self) self.setWindowIcon(QIcon("Images/UCIcon.png")) centralLayout = QVBoxLayout() centralWidget = QWidget() centralWidget.setLayout(centralLayout) self.setCentralWidget(centralWidget) self._tabWidget = QTabWidget() centralLayout.addWidget(self._tabWidget) menuBar = MenuBar() self.setMenuBar(menuBar) menuBar.saveProgram.connect( lambda: self._tabWidget.currentWidget().SaveProgram()) menuBar.closeProgram.connect( lambda: self.RequestCloseTab(self._tabWidget.currentIndex())) self._tabWidget.tabCloseRequested.connect(self.RequestCloseTab) self._tabWidget.setTabsClosable(True) timer = QTimer(self) timer.timeout.connect(self.CheckPrograms) timer.start(30)
def __init__(self): QWidget.__init__(self) self.expression = "" buttons = { "zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9", "comma": ".", "add": "+", "substract": "-", "multiply": "×", "divide": "÷", "power": "^", "openingParenthesis": "(", "closingParenthesis": ")" } for btn in buttons.items(): def fun(wtf=False, writes=btn[1]): self.expression += writes self.update() self.__setattr__(btn[0], fun) self.ui = Ui_Calculator() self.ui.setupUi(self) with open("qss/light.qss", "r") as f: self.setStyleSheet(f.read())
def setupUi(self, Form): if not Form.objectName(): Form.setObjectName(u"Form") Form.resize(403, 803) self.verticalLayout = QVBoxLayout(Form) self.verticalLayout.setObjectName(u"verticalLayout") self.viewTabs = QTabWidget(Form) self.viewTabs.setObjectName(u"viewTabs") self.viewTabs.setDocumentMode(False) self.viewTabs.setMovable(True) self.demoTab = QWidget() self.demoTab.setObjectName(u"demoTab") self.verticalLayout_9 = QVBoxLayout(self.demoTab) self.verticalLayout_9.setObjectName(u"verticalLayout_9") self.viewTabs.addTab(self.demoTab, "") self.previewTab = QWidget() self.previewTab.setObjectName(u"previewTab") self.verticalLayout_3 = QVBoxLayout(self.previewTab) self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.verticalLayout_2 = QVBoxLayout() self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.verticalLayout_3.addLayout(self.verticalLayout_2) self.viewTabs.addTab(self.previewTab, "") self.verticalLayout.addWidget(self.viewTabs) self.retranslateUi(Form) self.viewTabs.setCurrentIndex(0) QMetaObject.connectSlotsByName(Form)
def __init__(self): QWidget.__init__(self) self.model = CustomTableModel() self.table_view = QTableView() self.table_view.setModel(self.model) self.table_view.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) self.table_view.verticalHeader().setSectionResizeMode( QHeaderView.Stretch) self.chart = QtCharts.QChart() self.chart.setAnimationOptions(QtCharts.QChart.AllAnimations) self.series = QtCharts.QLineSeries() self.series.setName("Line 1") self.mapper = QtCharts.QVXYModelMapper(self) self.mapper.setXColumn(0) self.mapper.setYColumn(1) self.mapper.setSeries(self.series) self.mapper.setModel(self.model) self.chart.addSeries(self.series) # for storing color hex from the series seriesColorHex = "#000000" # get the color of the series and use it for showing the mapped area seriesColorHex = "{}".format(self.series.pen().color().name()) self.model.add_mapping(seriesColorHex, QRect(0, 0, 2, self.model.rowCount())) # series 2 self.series = QtCharts.QLineSeries() self.series.setName("Line 2") self.mapper = QtCharts.QVXYModelMapper(self) self.mapper.setXColumn(2) self.mapper.setYColumn(3) self.mapper.setSeries(self.series) self.mapper.setModel(self.model) self.chart.addSeries(self.series) # get the color of the series and use it for showing the mapped area seriesColorHex = "{}".format(self.series.pen().color().name()) self.model.add_mapping(seriesColorHex, QRect(2, 0, 2, self.model.rowCount())) self.chart.createDefaultAxes() self.chart_view = QtCharts.QChartView(self.chart) self.chart_view.setRenderHint(QPainter.Antialiasing) self.chart_view.setMinimumSize(640, 480) # create main layout self.main_layout = QGridLayout() self.main_layout.addWidget(self.table_view, 1, 0) self.main_layout.addWidget(self.chart_view, 1, 1) self.main_layout.setColumnStretch(1, 1) self.main_layout.setColumnStretch(0, 0) self.setLayout(self.main_layout)
def __init__(self): super().__init__() MANGA_ITEMS.itemClicked.connect(self.onSelectedManga) self.deletedManga.connect(self.onDeletedManga) self.selected = None self.summaries = {} for method_name, icon_path in self.BUTTONS: method = getattr(self, method_name) tooltip = f"{method_name.title()} a manga..." action = QAction() action.setToolTip(tooltip) action.setIcon(utils.icon(icon_path)) action.triggered.connect(method) button = QToolButton() button.setDefaultAction(action) self.addWidget(button) # spacer spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) self.addWidget(spacer) # text below the manga preview self.summary = QLabel() self.addWidget(self.summary) self.show()
def computeCenter(self): height = QWidget.height(self) width = QWidget.width(self) center_x = width / 2 center_y = height / 2 fontsizefactor = .38 if not self._hasFixedSize: if not self._hasFixedFontSize: mainradius = np.min( (width / 2 - self._ppMargin, height / (2 + 2 * fontsizefactor) - self._ppMargin)) mainradius = np.max((mainradius, 1)) center_y_pp = center_y + mainradius * fontsizefactor else: mainradius = np.min( (width / 2. - self._ppMargin, (height - 2 * self._fixedFontSize) / 2. - self._ppMargin)) mainradius = np.max((mainradius, 1)) center_y_pp = center_y + self._fixedFontSize else: mainradius = self._fixedSize / 2 mainradius = np.max((mainradius, 1)) center_y_pp = center_y + mainradius * fontsizefactor self.center = QtCore.QPointF(center_x, center_y_pp) self.mainRadius = mainradius return mainradius, fontsizefactor, center_x, center_y_pp, width
def add_unit(widget: QWidget, text: str) -> QWidget: h_layout = AHBoxLayout() h_layout.addWidget(widget) h_layout.addWidget(ALabel(text)) widget_with_label = QWidget() widget_with_label.setLayout(h_layout) return widget_with_label
def __init__(self, parent, name, data): QWidget.__init__(self, parent) DockContextHandler.__init__(self, self, name) self.actionHandler = UIActionHandler() self.actionHandler.setupActionHandler(self) status_layout = QHBoxLayout() status_layout.addWidget(QLabel('Status: ')) self.status = QLabel('idle') status_layout.addWidget(self.status) status_layout.setAlignment(QtCore.Qt.AlignCenter) client_dbg_layout = QHBoxLayout() client_dbg_layout.addWidget(QLabel('Client debugger: ')) self.client_dbg = QLabel('n/a') client_dbg_layout.addWidget(self.client_dbg) client_dbg_layout.setAlignment(QtCore.Qt.AlignCenter) client_pgm_layout = QHBoxLayout() client_pgm_layout.addWidget(QLabel('Client program: ')) self.client_pgm = QLabel('n/a') client_pgm_layout.addWidget(self.client_pgm) client_pgm_layout.setAlignment(QtCore.Qt.AlignCenter) layout = QVBoxLayout() layout.addStretch() layout.addLayout(status_layout) layout.addLayout(client_dbg_layout) layout.addLayout(client_pgm_layout) layout.addStretch() self.setLayout(layout)
def __init__(self, data): global instance_id QWidget.__init__(self) 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("Hello Pane", 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 = data # Populate initial state self.updateState() # Set up view and address change notifications self.notifications = HelloNotifications(self)
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__(self): QWidget.__init__(self) self.items = 0 # Example data self._data = { "Water": 24.5, "Electricity": 55.1, "Rent": 850.0, "Supermarket": 230.4, "Internet": 29.99, "Spätkauf": 21.85, "BVG Ticket": 60.0, "Coffee": 22.45, "Meetup": 0.0 } # Left self.table = QTableWidget() self.table.setColumnCount(2) self.table.setHorizontalHeaderLabels(["Description", "Quantity"]) self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) # QWidget Layout self.layout = QHBoxLayout() self.layout.addWidget(self.table) # Set the layout to the QWidget self.setLayout(self.layout) # Fill example data self.fill_table()
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, title, instructions, questions, answers, parent=None): super().__init__(parent) self.questions = questions self.answers = answers self.index = 0 self.mode = POSING_QUESTION self.button_labels = ['答え', '次の質問'] self.last_question = len(self.questions) - 1 self.setWindowTitle('日本語の練習') self.title = Title(title, self) self.instructions = Instructions(instructions, self) self.playfield = Playfield(self.questions[self.index], self.answers[self.index], self) self.controls = Controls(self, self.button_labels[self.mode], self.move_forward, self.quit_me) self.statusbar = self.statusBar() # Layout and hide the initial answer self.layout = QVBoxLayout() self.central_widget = QWidget() self.playfield.hide_answer() self.set_layout() self.setCentralWidget(self.central_widget) self.card_count = QLabel(f"{self.get_card_count()} cards") self.statusbar.addPermanentWidget(self.card_count)
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): super().__init__() self.setWindowTitle("Widgets App") layout = QVBoxLayout() widgets = [ QCheckBox, QComboBox, QDateEdit, QDateTimeEdit, QDial, QDoubleSpinBox, QFontComboBox, QLCDNumber, QLabel, QLineEdit, QProgressBar, QPushButton, QRadioButton, QSlider, QSpinBox, QTimeEdit, ] for w in widgets: layout.addWidget(w()) widget = QWidget() widget.setLayout(layout) # Set the central widget of the Window. Widget will expand # to take up all the space in the window by default. self.setCentralWidget(widget)
def __init__(self, song_similarity_list, similarity_scores): """Display all songs similar to one song :type song_similarity_list: list[Song] :param song_similarity_list: A list of similar songs :type similarity_scores: dict[tuple[Song, Song], int] :param similarity_scores: The similarity scores for each song pair""" super().__init__() self._song_similarity_list = song_similarity_list self._similarity_scores = similarity_scores self._diff_window_list = [] # Main layout self.resize(900, 600) self.setWindowTitle(self._song_similarity_list[0].get_name() + ' - Similar Songs') self.scrollableWrapper = QScrollArea() self.setCentralWidget(self.scrollableWrapper) self.centralLayout: QGridLayout = QGridLayout() self.centralWidget = QWidget() self.centralWidget.setLayout(self.centralLayout) self.scrollableWrapper.setWidget(self.centralWidget) self.scrollableWrapper.setWidgetResizable(True) # Add all similar songs row_num: int = 0 for song in self._song_similarity_list: button: QPushButton = QPushButton(song.get_name(), self) button.clicked.connect(partial(self.show_other_songs, song)) song.subscribe(Song.UPDATED, partial(self._song_updated, button)) self._song_updated(button, song) self.centralLayout.addWidget(button, row_num, 0) row_num += 1
def setEditorData(self, editor: QtWidgets.QWidget, index: QtCore.QModelIndex) -> None: editor = cast(QtWidgets.QDateEdit, editor) date_ = index.model().data(index, QtCore.Qt.DisplayRole) if date_.isNull(): date_ = QtCore.QDate.currentDate() editor.setDate(date_)
def __init__(self): super().__init__() layout = QVBoxLayout() self.progress = QProgressBar() button = QPushButton("START IT UP") button.pressed.connect(self.execute) self.status = QLabel("0 workers") layout.addWidget(self.progress) layout.addWidget(button) layout.addWidget(self.status) w = QWidget() w.setLayout(layout) # Dictionary holds the progress of current workers. self.worker_progress = {} self.setCentralWidget(w) self.show() self.threadpool = QThreadPool() print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount()) self.timer = QTimer() self.timer.setInterval(100) self.timer.timeout.connect(self.refresh_progress) self.timer.start()
class SideMenuWidget(QWidget): def __init__(self): super(SideMenuWidget, self).__init__() self.layout = QVBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(12) self.setLayout(self.layout) # PROFILE self.layout.addWidget(Profile()) # BUTTONS self.listview = ListView() self.listview.setFrameStyle(QFrame.NoFrame) self.listview.setFocusPolicy(Qt.NoFocus) self.listview.setModel(Model()) self.listview.setItemDelegate(Delegate()) self.layout.addWidget(self.listview) # LABELS self.labels = QWidget() self.labels.setFixedHeight(60) self.layout.addWidget(self.labels) _margins = 16 # left margin self.app_name = LinkLabel(self.labels, "color: rgba(0, 0, 0, 80%)", "color: rgba(0, 0, 0, 60%)") self.app_name.setText("sidemenu app") self.app_name.setFont(QFont("Roboto Light", 12)) self.app_name.move(self.labels.x() + _margins, self.labels.y()) self.app_ver = LinkLabel(self.labels, "color: rgba(0, 0, 0, 60%)", "color: rgba(0, 0, 0, 60%)") self.app_ver.setText("Версия 1.0.0") self.app_ver.setFont(QFont("Roboto Light", 11)) self.app_ver.move(self.labels.x() + _margins, self.labels.y() + _margins * 2) self.lbl = QLabel(self.labels) self.lbl.setText("-") self.lbl.setStyleSheet("color: rgba(0, 0, 0, 60%)") self.lbl.setFont(QFont("Roboto Light", 11)) self.lbl.move(self.labels.x() + _margins * 7, self.labels.y() + _margins * 2) self.app_about = LinkLabel(self.labels, "color: rgba(0, 0, 0, 60%)", "color: rgba(0, 0, 0, 60%)") self.app_about.setText("О программе") self.app_about.setFont(QFont("Roboto Light", 11)) self.app_about.move(self.labels.x() + _margins * 8, self.labels.y() + _margins * 2) self.setStyleSheet("background: white;") def paintEvent(self, event): opt = QStyleOption() opt.initFrom(self) p = QPainter(self) self.style().drawPrimitive(QStyle.PE_Widget, opt, p, self)
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, 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): super(MainWindow, self).__init__() self.threadpool = QtCore.QThreadPool() # 初始化线程池 print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount()) self.counter = 0 layout = QtWidgets.QVBoxLayout() self.l = QtWidgets.QLabel("Start") b = QtWidgets.QPushButton("DANGER!") b.pressed.connect(self.oh_no) layout.addWidget(self.l) layout.addWidget(b) w = QWidget() w.setLayout(layout) self.setCentralWidget(w) self.show() self.timer = QTimer() self.timer.setInterval(1000) self.timer.timeout.connect(self.recurring_timer) self.timer.start()
def __init__(self): QWidget.__init__(self) self.setMinimumSize(800, 600) self.donuts = [] self.chart_view = QChartView() self.chart_view.setRenderHint(QPainter.Antialiasing) self.chart = self.chart_view.chart() self.chart.legend().setVisible(False) self.chart.setTitle("Nested donuts demo") self.chart.setAnimationOptions(QChart.AllAnimations) self.min_size = 0.1 self.max_size = 0.9 self.donut_count = 5 self.setup_donuts() # create main layout self.main_layout = QGridLayout(self) self.main_layout.addWidget(self.chart_view, 1, 1) self.setLayout(self.main_layout) self.update_timer = QTimer(self) self.update_timer.timeout.connect(self.update_rotation) self.update_timer.start(1250)
def __init__(self, parent=None): QWidget.__init__(self) self.setParent(parent) # Set the colour of the overlay self.setStyleSheet("QWidget { background-color: rgba(255, 255, 255, 0.05)}") # Set OverlayTop heights # TODO: Change heights with increasing resolution self.setFixedHeight(50) # Create layout with margins/spacings layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) # Initialise MarqueeText self.marqueeText = self.MarqueeText(self) layout.addWidget(self.marqueeText, 0, 0, 2, 1) # Initialise search button self.initButton() layout.addWidget(self.button, 0, 1, 2, 1) # Initialise elapsedTime/localTime self.initTimes() layout.addWidget(self.elapsedTime, 0, 2, 1, 1) layout.addWidget(self.localTime, 1, 2, 1, 1) self.setLayout(layout)
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, song_orig, song_similar): """Displays the difference between two songs :type song_orig: Song.Song :param song_orig: The original song :type song_similar: Song.Song :param song_similar: The similar song """ super().__init__() self._song_orig = song_orig self._song_similar = song_similar # Setup gui self.resize(800, 550) self.setWindowTitle(self._song_orig.get_name() + ' - Similar Songs') self.scrollableWrapper: QScrollArea = QScrollArea() self.setCentralWidget(self.scrollableWrapper) self.centralLayout: QGridLayout = QGridLayout() self.centralLayout.setColumnStretch(0, 1) self.centralLayout.setColumnStretch(1, 30) self.centralLayout.setColumnStretch(2, 1) self.centralLayout.setColumnStretch(3, 30) self.centralWidget = QWidget() self.centralWidget.setLayout(self.centralLayout) self.scrollableWrapper.setWidget(self.centralWidget) self.scrollableWrapper.setWidgetResizable(True) # Show diff self._show_diff()
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()
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): 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)
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"))