def fill_pixels_within_circle(self, clicked_x, clicked_y): """ Add all highlighted pixels within the selected circle and updates the image. :param clicked_x: the current x coordinate :param clicked_y: the current y coordinate """ # Calculate euclidean distance between each highlighted point and # the clicked point. If the distance is less than the radius, # add it to the highlighted pixels. # Set of points to color points_to_color = set() # The roi drawn on current slice is changed after several pixels are # modified self.slice_changed = True clicked_x, clicked_y = linear_transform( clicked_x, clicked_y, self.rows, self.cols) scaled_tool_radius = int(self.draw_tool_radius * ( float(self.rows) / DEFAULT_WINDOW_SIZE)) min_y_bound_square = math.floor(clicked_y) - scaled_tool_radius min_x_bound_square = math.floor(clicked_x) - scaled_tool_radius max_y_bound_square = math.floor(clicked_y) + scaled_tool_radius max_x_bound_square = math.floor(clicked_x) + scaled_tool_radius for y_coord in range( max(self.min_y, min_y_bound_square), min(self.max_y, max_y_bound_square)): for x_coord in range( max(self.min_x, min_x_bound_square), min(self.max_x, max_x_bound_square)): clicked_point = numpy.array((clicked_x, clicked_y)) point_to_check = numpy.array((x_coord, y_coord)) distance = numpy.linalg.norm( clicked_point - point_to_check) if (self.keep_empty_pixel or self.min_pixel <= self.pixel_array[y_coord][ x_coord] <= self.max_pixel) \ and distance <= scaled_tool_radius: temp = set() temp.add((x_coord, y_coord)) points = get_pixel_coords(temp, self.rows, self.cols) temp_2 = get_first_entry(points) c = self.q_image.pixel(temp_2[0], temp_2[1]) colors = QColor(c) if (x_coord, y_coord) not in self.according_color_dict: self.according_color_dict[ (x_coord, y_coord)] = colors.getRgbF() points_to_color.add((x_coord, y_coord)) self.target_pixel_coords.add((x_coord, y_coord)) # Color to draw color_to_draw = QtGui.QColor() color_to_draw.setRgb(90, 250, 175, 200) points = get_pixel_coords(points_to_color, self.rows, self.cols) for x_coord, y_coord in points: self.q_image.setPixelColor(x_coord, y_coord, color_to_draw) self.refresh_image()
def paint(self, painter, option, index): super(Delegate, self).paint(painter, option, index) # HOVER if option.state & QStyle.State_MouseOver: painter.fillRect(option.rect, QColor("#F1F1F1")) else: painter.fillRect(option.rect, Qt.transparent) # SELECTED if option.state & QStyle.State_Selected: painter.fillRect(option.rect, QColor("#F1F1F1")) # DRAW ICON icon = QPixmap() icon.load(index.data()[1]) icon = icon.scaled(24, 24, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) left = 24 # margin left icon_pos = QRect(left, ((self._height - icon.height()) / 2) + option.rect.y(), icon.width(), icon.height()) painter.setRenderHint(QPainter.Antialiasing) painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.drawPixmap(icon_pos, icon) # DRAW TEXT font = QFont("Roboto Black", 12) text_pos = QRect((left * 2) + icon.width(), option.rect.y(), option.rect.width(), option.rect.height()) painter.setFont(font) painter.setPen(Qt.black) painter.drawText(text_pos, Qt.AlignVCenter, index.data()[0])
def __init__(self, name="?", r=10): super().__init__() self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsFocusable) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges) self.setCacheMode(QGraphicsItem.DeviceCoordinateCache) self.setAcceptHoverEvents(True) # define circle shape: w = 2 * r + 2 self.el = QGraphicsEllipseItem(0, 0, w, w) self.el.setBrush(QBrush(QColor("white"))) shadow = QGraphicsDropShadowEffect() shadow.setOffset(4) self.el.setGraphicsEffect(shadow) self.el.setParentItem(self) # define node label shape: self.label = QGraphicsTextItem(name) self.label.setDefaultTextColor(QColor("blue")) self.label.setFlag(QGraphicsItem.ItemIsSelectable) self.label.setParentItem(self) self.el.setZValue(1.0) self.label.setZValue(2.0) center = self.center() - self.label.boundingRect().center() self.label.setPos(self.mapFromScene(center)) self.setZValue(1.0) self.cx = []
def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.fill_color = QColor(30, 30, 30, 120) self.text_color = QColor(255, 255, 255, 255) self.message.setStyleSheet('color: white')
def __init__(self, parent: Qtw.QWidget, text: str, ioType: str = 'in'): super(Patchpoint, self).__init__(parent) self._ppMargin = 3 self._hasFixedSize = False self._hasFixedFontSize = False self._text = text self.title = text self._fixedSize = 0 self._fixedFontSize = 0 self.setMinimumSize(QSize(36, 36)) self.center = QtCore.QPointF(0, 0) self.mainRadius = 0 if (ioType == 'in') or (ioType == 'out'): self.io = ioType else: self.io = 'in' self.lastPc = None self.pcs = PatchCordList() self.hasPcGrabbed = False self._ppColor = QColor("black") self.bgColor = QColor("blue") self.pointColor = QColor("red") self.setMouseTracking(True) self.fontsize = -1
def __update_file_status(self, item: EssStandardItem): stat = get_from_essharp(item.accessibleText(), "s") if not len(stat): logging.error("get_from_essharp fail: " + item.accessibleText()) return parent = item.parent() if parent is None: name_col = self.__ess_file_model.item( item.row(), ITEM_PROPERTIES.index("user")) date_col = self.__ess_file_model.item( item.row(), ITEM_PROPERTIES.index("date")) else: name_col = parent.child(item.row(), ITEM_PROPERTIES.index("user")) date_col = parent.child(item.row(), ITEM_PROPERTIES.index("date")) if stat["ischeckout"]: name_col.setText(stat["checkout_info"]["user_name"]) date_col.setText(stat["checkout_info"]["date"]) item.setForeground(QBrush(QColor("red"))) set_icon(item, u":/checkout/checkoutline02.svg") else: name_col.setText(stat["version_info"]["user_name"]) date_col.setText(stat["version_info"]["date"]) item.setForeground(QBrush(QColor("black"))) set_icon(item, u":/file/file.svg")
def drawSquare(self, painter, x, y, shape): """ Draws a square of a shape """ color = self.curPiece.COLOR_TABLE color = QColor(color[shape]) painter.fillRect(x + 1, y + 1, self.get_square_width() - 2, self.get_square_height() - 2, color) painter.setPen(color.lighter()) painter.drawLine(x, y + self.get_square_height() - 1, x, y) painter.drawLine(x, y, x + self.get_square_width() - 1, y) painter.setPen(color.darker()) painter.drawLine(x + 1, y + self.get_square_height() - 1, x + self.get_square_width() - 1, y + self.get_square_height() - 1) painter.drawLine(x + self.get_square_width() - 1, y + self.get_square_height() - 1, x + self.get_square_width() - 1, y + 1)
def __init__(self, parent=None): super(ffmpeg, self).__init__(parent) self.add_mapping(r'\$', setFontItalic=True, setBackground=QColor('#ff007f')) self.add_mapping(r'##.*?##', setFontItalic=True, setBackground=QColor('#ff007f'))
def __init__(self, parent): QWidget.__init__(self, parent) self.charts = [] self.ui = ui() self.list_count = 3 self.value_max = 10 self.value_count = 7 self.data_table = self.generate_random_data(self.list_count, self.value_max, self.value_count) self.ui.setupUi(self) self.populate_themebox() self.populate_animationbox() self.populate_legendbox() # Area Chart chart_view = QtCharts.QChartView(self.create_areachart()) self.ui.gridLayout.addWidget(chart_view, 1, 0) self.charts.append(chart_view) # Pie Chart chart_view = QtCharts.QChartView(self.createPieChart()) chart_view.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) self.ui.gridLayout.addWidget(chart_view, 1, 1) self.charts.append(chart_view) # Line Chart chart_view = QtCharts.QChartView(self.createLineChart()) self.ui.gridLayout.addWidget(chart_view, 1, 2) self.charts.append(chart_view) # Bar Chart chart_view = QtCharts.QChartView(self.createBarChart()) self.ui.gridLayout.addWidget(chart_view, 2, 0) self.charts.append(chart_view) # Spline Chart chart_view = QtCharts.QChartView(self.createSplineChart()) self.ui.gridLayout.addWidget(chart_view, 2, 1) self.charts.append(chart_view) # Scatter Chart chart_view = QtCharts.QChartView(self.create_scatterchart()) self.ui.gridLayout.addWidget(chart_view, 2, 2) self.charts.append(chart_view) # Set defaults self.ui.antialiasCheckBox.setChecked(True) # Set the colors from the light theme as default ones pal = qApp.palette() pal.setColor(QPalette.Window, QColor(0xf0f0f0)) pal.setColor(QPalette.WindowText, QColor(0x404044)) qApp.setPalette(pal) self.updateUI()
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 refreshProteinsTableWidget(self) -> None: search_text = self.proteinsSearchLineEdit.text().strip() search_mode = self.proteinsSearchTypeComboBox.currentIndex() if not search_text: return if search_mode == 0: results = self._database.search_proteins_by_name( search_text, limit=10000, callback=self._progressCallback) elif search_mode == 1: results = self._database.search_proteins_by_sequence( search_text, limit=10000, callback=self._progressCallback) elif search_mode == 2: try: digestion_settings = self._working_digestion_action_group.checkedAction( ).data() except AttributeError: results = [] else: results = self._database.search_proteins_by_peptide_sequence( search_text, digestion_settings, limit=10000, callback=self._progressCallback) else: raise ValueError self.proteinsTableWidget.setRowCount(0) self.proteinsTableWidget.setSortingEnabled(False) try: for i, protein in enumerate(results): self.proteinsTableWidget.insertRow(i) index_item = QTableWidgetItem(str(i + 1).zfill(5)) index_item.setData(TableItemDataRole.ROW_OBJECT, protein) name_item = QTableWidgetItem(protein.name) self.proteinsTableWidget.setItem(i, 0, index_item) self.proteinsTableWidget.setItem(i, 1, name_item) except ResultsLimitExceededError: commondialog.informationMessage( self, 'Your search returns too much results.\n' 'Only the 10000 first results will be displayed.', dismissable=True) self.proteinsTableWidget.setSortingEnabled(True) self.proteinsTableWidget.resizeColumnToContents(-1) # Change search line edit text color to assure the user the search is done palette = self.proteinsSearchLineEdit.palette() if self.proteinsTableWidget.rowCount(): palette.setColor(QPalette.Text, QColor(0, 180, 0)) else: palette.setColor(QPalette.Text, QColor(180, 0, 0)) self.proteinsSearchLineEdit.setPalette(palette)
def create_blue_green_rect(): pixmap = QPixmap(4, 2) painter = QPainter(pixmap) try: painter.fillRect(0, 0, 2, 2, QColor('blue')) painter.fillRect(2, 0, 2, 2, QColor('green')) finally: painter.end() return pixmap
def data(self, index, role): """Cell content.""" if role == Qt.DisplayRole: return self._list[index.row()][index.column()] elif role == Qt.BackgroundRole: if self._is_header(index.row()): return QColor(Qt.darkGreen) elif role == Qt.ForegroundRole: if self._is_header(index.row()): return QColor(Qt.white)
def data(self, index, role=Qt.DisplayRole): if role == Qt.DisplayRole: return self.input_data[index.row()][index.column()] elif role == Qt.EditRole: return self.input_data[index.row()][index.column()] elif role == Qt.BackgroundRole: for color, rect in self.mapping.items(): if rect.contains(index.column(), index.row()): return QColor(color) # cell not mapped return white color return QColor(Qt.white) return None
def hue_rotate_color(original_color: tuple[int, int, int], rotation: int): color = QColor.fromRgb(*original_color) h = color.hue() + rotation s = color.saturation() v = color.value() while h >= 360: h -= 360 while h < 0: h += 360 rotated_color = QColor.fromHsv(h, s, v) return (rotated_color.red(), rotated_color.green(), rotated_color.blue())
def run(self): enabled_sid_list = get_enabled_sid_list() for i in range(ui.tableWidget.rowCount()): status = '未解锁' if str( ui.tableWidget.item(i, 4).data( Qt.ItemDataRole.DisplayRole)) in enabled_sid_list: status = '已解锁' ui.tableWidget.item(i, 1).setText(status) if status == '已解锁': ui.tableWidget.item(i, 1).setBackground(QColor(0, 255, 0, 127)) else: ui.tableWidget.item(i, 1).setBackground(QColor(255, 0, 0, 127))
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 __init__(self): self.options = { 'units': 'px', # px / cm / inch 'always_above': False, 'horizontal_orientation': True, 'background_color': QColor(222, 212, 33, 210), 'lines_color': QColor(0, 0, 0, 255), 'divisions_color': QColor(0, 0, 255, 255), 'ruler_width': 500, 'ruler_height': 50, 'options_opened': False, 'division_lines': False, } self.load()
def toggle_attached(self): legend = self.chart.legend() if legend.isAttachedToChart(): legend.detachFromChart() legend.setBackgroundVisible(True) legend.setBrush(QBrush(QColor(128, 128, 128, 128))) legend.setPen(QPen(QColor(192, 192, 192, 192))) self.show_legend_spinbox() self.update_legend_layout() else: legend.attachToChart() legend.setBackgroundVisible(False) self.hideLegendSpinbox() self.update()
def __init__( self, displayed_columns: Sequence[Column], color: QtGui.QColor, parent: QtWidgets.QWidget) -> None: super().__init__(parent) self._displayed_columns = displayed_columns self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection) self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self._open_context_menu) self.setRootIsDecorated(False) self.setEditTriggers( QtWidgets.QAbstractItemView.EditKeyPressed | QtWidgets.QAbstractItemView.AnyKeyPressed | QtWidgets.QAbstractItemView.SelectedClicked | QtWidgets.QAbstractItemView.DoubleClicked) self.setAlternatingRowColors(True) palette = self.palette() base_color = color.lighter(115) palette.setColor(QtGui.QPalette.Base, base_color) palette.setColor(QtGui.QPalette.AlternateBase, color) self.setPalette(palette) self.setStyleSheet( "QHeaderView::section {" "background-color: rgb(114, 118, 138);" "border: none;" "}") self.header().setSortIndicatorShown(True) self.header().setSectionsClickable(True) self.setSortingEnabled(True) self.setItemsExpandable(False)
def createRenderer(self): self._renderer = _NodeGLRenderer(self.window()) livectls = ngl.get_livectls(self._scene) if livectls: model_data = [] for label, ctl in livectls.items(): data = dict( type=self._NODE_TYPES_MODEL_MAP.get( ctl["node_type"], "range"), label=label, val=ctl["val"], node=ctl["node"], ) if data["type"] not in ("bool", "text"): data["min"] = ctl["min"] data["max"] = ctl["max"] if data["type"] == "color": data["val"] = QColor.fromRgbF(*ctl["val"]) model_data.append(data) self.livectls_changes = {} self.livectls_changed.emit(model_data) self.request_scene = self._scene return self._renderer
def add_breakdown_series(self, breakdown_series, color): font = QFont("Arial", 8) # add breakdown series as a slice to center pie main_slice = MainSlice(breakdown_series) main_slice.setName(breakdown_series.name()) main_slice.setValue(breakdown_series.sum()) self.main_series.append(main_slice) # customize the slice main_slice.setBrush(color) main_slice.setLabelVisible() main_slice.setLabelColor(Qt.white) main_slice.setLabelPosition(QtCharts.QPieSlice.LabelInsideHorizontal) main_slice.setLabelFont(font) # position and customize the breakdown series breakdown_series.setPieSize(0.8) breakdown_series.setHoleSize(0.7) breakdown_series.setLabelsVisible() for pie_slice in breakdown_series.slices(): color = QColor(color).lighter(115) pie_slice.setBrush(color) pie_slice.setLabelFont(font) # add the series to the chart self.addSeries(breakdown_series) # recalculate breakdown donut segments self.recalculate_angles() # update customize legend markers self.update_legend_markers()
def draw_cursor(self, event_x, event_y, drawing_tool_radius, new_circle=False): """ Draws a blue circle where the user clicked. :param event_x: QGraphicsScene event attribute: event.scenePos().x() :param event_y: QGraphicsScene event attribute: event.scenePos().y() :param drawing_tool_radius: the current radius of the drawing tool :param new_circle: True when the circle object is being created rather than updated. """ self.draw_tool_radius = drawing_tool_radius self.current_cursor_x = event_x - self.draw_tool_radius self.current_cursor_y = event_y - self.draw_tool_radius if new_circle: self.cursor = QGraphicsEllipseItem(self.current_cursor_x, self.current_cursor_y, self.draw_tool_radius * 2, self.draw_tool_radius * 2) pen = QPen(QColor("blue")) pen.setWidth(0) self.cursor.setPen(pen) self.cursor.setZValue(1) self.addItem(self.cursor) elif self.cursor is not None: self.cursor.setRect(self.current_cursor_x, self.current_cursor_y, self.draw_tool_radius * 2, self.draw_tool_radius * 2)
def get_annotation(self) -> Annotation: return Annotation(RomVariant(self.ui.lineEditVariant.text()), parse_address(self.ui.lineEditAddress.text()), self.ui.spinBoxLength.value(), QColor(self.ui.lineEditColor.text()), self.ui.lineEditAuthor.text(), self.ui.plainTextEditNote.toPlainText().strip())
def paintEvent(self, event): """ Поскольку это полностью прозрачное фоновое окно, жесткая для поиска граница с прозрачностью 1 рисуется в событии перерисовывания, чтобы отрегулировать размер окна. """ super(FramelessWindow, self).paintEvent(event) painter = QPainter(self) painter.setPen(QPen(QColor(255, 255, 255, 1), 2 * self.Margins)) painter.drawRect(self.rect())
def __init__(self, parent=None): super(qml, self).__init__(parent) self.add_mapping(r'\b(console|readonly|function|import)\b', setForeground=QColor('#442200')) self.add_mapping(r'^\s*(\w+)\s*{\s*$', setForeground=Qt.blue) self.add_mapping(r'^\s*(import).*$', setFontItalic=True, setForeground=QColor('#aa5500')) self.add_mapping(r'^\s*(readonly)?\s*(property).*', setForeground=Qt.blue, setFontItalic=True) self.add_mapping(r'^\s*(import).*$', setForeground=Qt.blue, setFontItalic=True) self.add_mapping(r'//.*$', setBackground=QColor('#77ff77')) self.add_mapping(r'["\'][^"\']+["\']', setForeground=QColor('#ff0000'))
def _display_pixel_color(self): """ Creates the initial list of pixel values within the given minimum and maximum densities, then displays them on the view. """ if self.min_pixel <= self.max_pixel: data_set = self.dataset if hasattr(self.draw_roi_window_instance, 'bounds_box_draw'): bound_box = \ self.draw_roi_window_instance.bounds_box_draw.box.rect() self.min_x, self.min_y = linear_transform( bound_box.x(), bound_box.y(), self.rows, self.cols ) self.max_x, self.max_y = linear_transform( bound_box.width(), bound_box.height(), self.rows, self.cols ) self.max_x += self.min_x self.max_y += self.min_y else: self.min_x = 0 self.min_y = 0 self.max_x = self.rows self.max_y = self.cols """pixel_array is a 2-Dimensional array containing all pixel coordinates of the q_image. pixel_array[x][y] will return the density of the pixel """ self.pixel_array = data_set._pixel_array self.q_image = self.img.toImage() for y_coord in range(self.min_y, self.max_y): for x_coord in range(self.min_x, self.max_x): if (self.pixel_array[y_coord][x_coord] >= self.min_pixel) \ and (self.pixel_array[y_coord][ x_coord] <= self.max_pixel): self.target_pixel_coords.add((x_coord, y_coord)) """For the meantime, a new image is created and the pixels specified are coloured. This will need to altered so that it creates a new layer over the existing image instead of replacing it. """ # Convert QPixMap into Qimage for x_coord, y_coord in self.target_pixel_coords: temp = set() temp.add((x_coord, y_coord)) points = get_pixel_coords(temp, self.rows, self.cols) temp_2 = get_first_entry(points) c = self.q_image.pixel(temp_2[0], temp_2[1]) colors = QColor(c).getRgbF() self.according_color_dict[(x_coord, y_coord)] = colors color = QtGui.QColor() color.setRgb(90, 250, 175, 200) points = get_pixel_coords(self.according_color_dict, self.rows, self.cols) for x_coord, y_coord in points: self.q_image.setPixelColor(x_coord, y_coord, color) self.refresh_image()
def __init__(self, rows: int, cols: int, target: QPaintDevice, rect: QRect = None, clues: typing.Dict[str, str] = None, row_clues: typing.Iterable[QPixmap] = None, column_clues: typing.Iterable[QPixmap] = None): """ Initialize the object. :param rows: the number of rows to break the art into :param cols: the number of columns to break the art into :param target: what to paint the pieces on :param rect: where to paint the pieces, or None to use the full target :param clues: word clues to display, defaults to just the letters :param row_clues: one image to use as a clue for each row :param column_clues: one image to use as a clue for each column """ self.rows = rows self.cols = cols self.target = target self.rect = rect or QRect(0, 0, target.width(), target.height()) self.cells = [(i, j, chr(65 + k)) for k, (i, j) in enumerate( (i, j) for i in range(rows) for j in range(cols))] self.is_shuffled = False self.clues = clues or {} self.row_clues = [] if row_clues is None else list(row_clues) self.column_clues = [] if column_clues is None else list(column_clues) self.row_clue_rects: typing.List[QRect] = [] self.column_clue_rects: typing.List[QRect] = [] self.background = QColor('white') self.selected_row = self.selected_column = None
def __init__(self, base_path, file, file_config, parent=None): super().__init__(parent) board = BanBoard(file, file_config) board_area = QScrollArea() board_area.setWidget(board) board_area.setWidgetResizable(True) self.setCentralWidget(board_area) self.stbar = QStatusBar() # add a save button at the right bottom corner save_btn = BanButton( "save", objectName="appBtn_save", toolTip="save xban file", shortcut="Ctrl+S", ) shadow = QGraphicsDropShadowEffect(self, blurRadius=10, offset=5, color=QColor("lightgrey")) save_btn.setGraphicsEffect(shadow) save_btn.pressed.connect(board.save_board) self.stbar.addPermanentWidget(save_btn) self.setStatusBar(self.stbar) log_handler = QLogHandler(self) root_logger = logging.getLogger() root_logger.addHandler(log_handler) log_handler.signal.log_msg.connect( partial(self.stbar.showMessage, timeout=1500)) self.stbar.showMessage(f"Initiate {file}", 1500) self.show()
def paint(self, painter: QPainter): brush = QBrush(QColor("#007430")) painter.setBrush(brush) painter.setPen(Qt.NoPen) painter.setRenderHint(QPainter.Antialiasing) itemSize = self.size() painter.drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10) if self.rightAligned: points = [ QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0), QPointF(itemSize.width() - 20.0, itemSize.height()), QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0), ] else: points = [ QPointF(10.0, itemSize.height() - 10.0), QPointF(20.0, itemSize.height()), QPointF(30.0, itemSize.height() - 10.0), ] painter.drawConvexPolygon(points)