我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用PyQt5.QtCore.Qt.transparent()。
def saveFrame(self, frame): fileName = self._fileName if self._frameCounter: index = fileName.rfind('.') fileName = "%s_frame%s%s" % (fileName[:index], self._frameCounter, fileName[index:]) image = QImage(frame.contentsSize(), QImage.Format_ARGB32_Premultiplied) image.fill(Qt.transparent) painter = QPainter(image) painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.TextAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) frame.documentElement().render(painter) painter.end() image.save(fileName) self._frameCounter += 1 for childFrame in frame.childFrames(): self.saveFrame(childFrame)
def __init__(self, *args, fillcolor, opacity, parent=None): if len(args) == 0: super().__init__(parent) elif len(args) == 1: super().__init__(args[0], parent) elif len(args) == 4: x0, y0, w, h = args super().__init__(x0, y0, w, h, parent) self.finished = False self.selected_edge = None # type: int self.resizing = False self.setBrush(fillcolor) self.setPen(QPen(QColor(Qt.transparent), Qt.FlatCap)) self.setOpacity(opacity)
def dialog_ui(self) -> QDialog: if self.__dialog_ui is None: dir_name = os.path.dirname(os.readlink(__file__)) if os.path.islink(__file__) else os.path.dirname(__file__) self.__dialog_ui = uic.loadUi(os.path.realpath(os.path.join(dir_name, "insert_sine_dialog.ui"))) self.__dialog_ui.setAttribute(Qt.WA_DeleteOnClose) self.__dialog_ui.setModal(True) self.__dialog_ui.doubleSpinBoxAmplitude.setValue(self.__amplitude) self.__dialog_ui.doubleSpinBoxFrequency.setValue(self.__frequency) self.__dialog_ui.doubleSpinBoxPhase.setValue(self.__phase) self.__dialog_ui.doubleSpinBoxSampleRate.setValue(self.__sample_rate) self.__dialog_ui.doubleSpinBoxNSamples.setValue(self.__num_samples) self.__dialog_ui.lineEditTime.setValidator( QRegExpValidator(QRegExp("[0-9]+([nmµ]*|([\.,][0-9]{1,3}[nmµ]*))?$"))) scene_manager = SceneManager(self.dialog_ui.graphicsViewSineWave) self.__dialog_ui.graphicsViewSineWave.scene_manager = scene_manager self.insert_indicator = scene_manager.scene.addRect(0, -2, 0, 4, QPen(QColor(Qt.transparent), Qt.FlatCap), QBrush(self.INSERT_INDICATOR_COLOR)) self.insert_indicator.stackBefore(scene_manager.scene.selection_area) self.set_time() return self.__dialog_ui
def _add_latest_input_line(self, angle): """Adds a line to the graphic scene that visualizes a scanned angle""" mx, my = self._get_middle() angle_rad = deg2rad(angle) angle_1_rad = deg2rad(angle - self.measurement_angle/2.0) angle_2_rad = deg2rad(angle + self.measurement_angle/2.0) length = max(self.width(), self.height()) start_point = (mx, my) p1 = (mx + length * math.cos(angle_1_rad), my + length * math.sin(angle_1_rad)) p2 = (mx + length * math.cos(angle_2_rad), my + length * math.sin(angle_2_rad)) gradient_start_point, gradient_end_point = (mx, my), (mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad)) gradient = QLinearGradient(*gradient_start_point, *gradient_end_point) gradient.setColorAt(0, Qt.transparent) gradient.setColorAt(0.8, Qt.red) gradient.setColorAt(1, Qt.darkRed) triangle = QPolygonF() triangle.append(QPointF(*start_point)) triangle.append(QPointF(*p1)) triangle.append(QPointF(*p2)) triangle.append(QPointF(*start_point)) self.scene.addPolygon(triangle, pen=QPen(Qt.transparent), brush=QBrush(gradient))
def drawIndicatorIcon(palette, style): pix = QPixmap(14, 14) pix.fill(Qt.transparent) branchOption = QStyleOption() #r = QRect(QPoint(0, 0), pix.size()) branchOption.rect = QRect(2, 2, 9, 9) ## ### hardcoded in qcommonstyle.cpp branchOption.palette = palette branchOption.state = QStyle.State_Children p = QPainter() ## Draw closed state p.begin(pix) style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p) p.end() rc = QIcon(pix) rc.addPixmap(pix, QIcon.Selected, QIcon.Off) ## Draw opened state branchOption.state |= QStyle.State_Open pix.fill(Qt.transparent) p.begin(pix) style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p) p.end() rc.addPixmap(pix, QIcon.Normal, QIcon.On) rc.addPixmap(pix, QIcon.Selected, QIcon.On) return rc
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex) -> None: r = option.rect pencolor = Qt.white if self.theme == 'dark' else Qt.black if self.parent.isEnabled(): if option.state & QStyle.State_Selected: painter.setBrush(QColor(150, 190, 78, 150)) elif option.state & QStyle.State_MouseOver: painter.setBrush(QColor(227, 212, 232)) pencolor = Qt.black else: brushcolor = QColor(79, 85, 87, 175) if self.theme == 'dark' else QColor('#EFF0F1') painter.setBrush(Qt.transparent if index.row() % 2 == 0 else brushcolor) painter.setPen(Qt.NoPen) painter.drawRect(r) thumb = QIcon(index.data(Qt.DecorationRole + 1)) starttime = index.data(Qt.DisplayRole + 1) endtime = index.data(Qt.UserRole + 1) externalPath = index.data(Qt.UserRole + 2) r = option.rect.adjusted(5, 0, 0, 0) thumb.paint(painter, r, Qt.AlignVCenter | Qt.AlignLeft) painter.setPen(QPen(pencolor, 1, Qt.SolidLine)) r = option.rect.adjusted(110, 8, 0, 0) painter.setFont(QFont('Noto Sans UI', 10 if sys.platform == 'darwin' else 8, QFont.Bold)) painter.drawText(r, Qt.AlignLeft, 'FILENAME' if len(externalPath) else 'START') r = option.rect.adjusted(110, 20, 0, 0) painter.setFont(QFont('Noto Sans UI', 11 if sys.platform == 'darwin' else 9, QFont.Normal)) if len(externalPath): painter.drawText(r, Qt.AlignLeft, self.clipText(os.path.basename(externalPath), painter)) else: painter.drawText(r, Qt.AlignLeft, starttime) if len(endtime) > 0: r = option.rect.adjusted(110, 45, 0, 0) painter.setFont(QFont('Noto Sans UI', 10 if sys.platform == 'darwin' else 8, QFont.Bold)) painter.drawText(r, Qt.AlignLeft, 'RUNTIME' if len(externalPath) else 'END') r = option.rect.adjusted(110, 60, 0, 0) painter.setFont(QFont('Noto Sans UI', 11 if sys.platform == 'darwin' else 9, QFont.Normal)) painter.drawText(r, Qt.AlignLeft, endtime) if self.parent.verticalScrollBar().isVisible(): self.parent.setFixedWidth(210) else: self.parent.setFixedWidth(190)
def __init__(self, parent=None, interval=50): QWidget.__init__(self, parent) palette = QPalette(self.palette()) palette.setColor(palette.Background, Qt.transparent) self.setPalette(palette) self.counter = 0 self.interval = interval
def applyEffectToPixmap(pixmap, effect): scene = QGraphicsScene() item = QGraphicsPixmapItem() item.setPixmap(pixmap) item.setGraphicsEffect(effect) scene.addItem(item) res = QPixmap(pixmap.size()) res.fill(Qt.transparent) painter = QPainter(res) scene.render(painter) return res
def clearChart(self): self.color = QColor(Qt.transparent) self.update() self.chartCleared.emit()
def clearChart(self): self.color = QColor(Qt.transparent) self.update()
def __init__(self, project_manager, modulated_data, modulation_msg_indices=None, parent=None, testing_mode=False): super().__init__(project_manager, is_tx=True, parent=parent, testing_mode=testing_mode) self.graphics_view = self.ui.graphicsViewSend self.ui.stackedWidget.setCurrentWidget(self.ui.page_send) self.hide_receive_ui_items() self.ui.btnStart.setIcon(QIcon.fromTheme("media-playback-start")) self.setWindowTitle("Send Signal") self.setWindowIcon(QIcon.fromTheme("media-playback-start")) self.ui.btnStart.setToolTip("Send data") self.ui.btnStop.setToolTip("Stop sending") self.device_is_sending = False self.modulation_msg_indices = modulation_msg_indices if self.modulation_msg_indices is not None: self.ui.progressBarMessage.setMaximum(len(self.modulation_msg_indices)) else: self.ui.progressBarMessage.hide() self.ui.labelCurrentMessage.hide() if modulated_data is not None: # modulated_data is none in continuous send mode self.ui.progressBarSample.setMaximum(len(modulated_data)) samp_rate = self.ui.spinBoxSampleRate.value() signal = Signal.from_samples(modulated_data, "Modulated Preview", samp_rate) self.scene_manager = SignalSceneManager(signal, parent=self) self.send_indicator = self.scene_manager.scene.addRect(0, -2, 0, 4, QPen(QColor(Qt.transparent), Qt.FlatCap), QBrush(constants.SEND_INDICATOR_COLOR)) self.send_indicator.stackBefore(self.scene_manager.scene.selection_area) self.scene_manager.init_scene() self.graphics_view.set_signal(signal) self.graphics_view.sample_rate = samp_rate self.init_device() self.graphics_view.setScene(self.scene_manager.scene) self.graphics_view.scene_manager = self.scene_manager self.create_connects()
def getPixmap(self): pixmap = QPixmap(self.width * self.pixelRatio, self.height * self.pixelRatio) pixmap.setDevicePixelRatio(self.pixelRatio) pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.setRenderHint(QPainter.Antialiasing) painter.translate(0, self.height) painter.scale(1, -1) if self.headerAtBottom: bodyRect = (0, 0, self.width, self.height-self.headerHeight) headerRect = (0, 0, self.width, self.headerHeight) else: bodyRect = (0, 0, self.width, self.height-self.headerHeight) headerRect = (0, 0, self.width, self.headerHeight) # background painter.save() if self.headerAtBottom: h = self.height else: h = self.height - self.headerHeight painter.translate(0, h) painter.scale(1, -1) self.drawCellBackground(painter, bodyRect) painter.restore() # glyph if self.headerAtBottom: painter.translate(0, self.headerHeight) if self.shouldDrawMetrics: self.drawCellHorizontalMetrics(painter, bodyRect) self.drawCellVerticalMetrics(painter, bodyRect) painter.save() painter.setClipRect(0, 0, self.width, self.height-self.headerHeight) painter.translate(self.xOffset, self.yOffset) painter.scale(self.scale, self.scale) self.drawCellGlyph(painter) painter.restore() # foreground painter.save() painter.translate(0, self.height - self.headerHeight) painter.scale(1, -1) self.drawCellForeground(painter, bodyRect) painter.restore() # header if self.shouldDrawHeader: painter.save() if self.headerAtBottom: h = 0 else: h = self.height painter.translate(0, h) painter.scale(1, -1) self.drawCellHeaderBackground(painter, headerRect) self.drawCellHeaderText(painter, headerRect) painter.restore() return pixmap
def setupScene(self): self.m_scene.setSceneRect(-300, -200, 600, 460) linearGrad = QLinearGradient(QPointF(-100, -100), QPointF(100, 100)) linearGrad.setColorAt(0, QColor(255, 255, 255)) linearGrad.setColorAt(1, QColor(192, 192, 255)) self.setBackgroundBrush(linearGrad) radialGrad = QRadialGradient(30, 30, 30) radialGrad.setColorAt(0, Qt.yellow) radialGrad.setColorAt(0.2, Qt.yellow) radialGrad.setColorAt(1, Qt.transparent) pixmap = QPixmap(60, 60) pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.setPen(Qt.NoPen) painter.setBrush(radialGrad) painter.drawEllipse(0, 0, 60, 60) painter.end() self.m_lightSource = self.m_scene.addPixmap(pixmap) self.m_lightSource.setZValue(2) for i in range(-2, 3): for j in range(-2, 3): if (i + j) & 1: item = QGraphicsEllipseItem(0, 0, 50, 50) else: item = QGraphicsRectItem(0, 0, 50, 50) item.setPen(QPen(Qt.black, 1)) item.setBrush(QBrush(Qt.white)) effect = QGraphicsDropShadowEffect(self) effect.setBlurRadius(8) item.setGraphicsEffect(effect) item.setZValue(1) item.setPos(i * 80, j * 80) self.m_scene.addItem(item) self.m_items.append(item)