当前位置: 首页>>代码示例>>Python>>正文


Python Qt.KeepAspectRatio方法代码示例

本文整理汇总了Python中PyQt5.QtCore.Qt.KeepAspectRatio方法的典型用法代码示例。如果您正苦于以下问题:Python Qt.KeepAspectRatio方法的具体用法?Python Qt.KeepAspectRatio怎么用?Python Qt.KeepAspectRatio使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtCore.Qt的用法示例。


在下文中一共展示了Qt.KeepAspectRatio方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _paint_frame

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def _paint_frame(self, event):
        if self.bgimage:
            pixmap = self._build_pixmap(self.bgimage)
            # Check we need to resize the bgimage
            if self.bgsize:
                bgsize = self.bgsize
                if self.bgsize == 'fit':
                    bgsize = self.size()
                pixmap = pixmap.scaled(bgsize, Qt.KeepAspectRatio, Qt.SmoothTransformation)
            # Calculate the x,y position
            x,y = self.bgpos
            if self.bgpos:
                if x == 'left': x = 0
                elif x == 'center': x = (self.width() / 2) - (pixmap.width() / 2)
                elif x == 'right': x = self.width() - pixmap.width()
                if y == 'top': y = 0
                elif y == 'center': y = (self.height() / 2) - (pixmap.height() / 2)
                elif y == 'bottom': y = self.height() - pixmap.height()
            # Draw the pixmap
            painter = QtGui.QPainter(self)
            painter.setOpacity(self.bgopacity)
            painter.drawPixmap(int(x), int(y), pixmap) 
开发者ID:pkkid,项目名称:pkmeter,代码行数:24,代码来源:pkmixins.py

示例2: set_status

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def set_status(self, raw, exist=None):
        item = QLabel()
        item.setAlignment(Qt.AlignCenter)

        if exist is 0:
            icon = QPixmap(QUEUE_ICON).scaled(20, 20, Qt.KeepAspectRatio,
                                              Qt.SmoothTransformation)
            item.setPixmap(icon)
            item.setToolTip('Waiting in the download queue...')

        if exist is 1:
            icon = QPixmap(CHECK_ICON).scaled(20, 20, Qt.KeepAspectRatio,
                                              Qt.SmoothTransformation)
            item.setPixmap(icon)
            item.setToolTip('All the features are downloaded...')

        if exist is 2:
            item = QPushButton(self)
            item.setToolTip('Download')
            item.setIcon(QIcon(DOWNLOAD_ICON))
            item.clicked.connect(self.download_clicked)

        self.setCellWidget(raw, 0, item) 
开发者ID:MTG,项目名称:dunya-desktop,代码行数:25,代码来源:table.py

示例3: __init__

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def __init__(self,parent="None",title="None",description="None",url="None",urlImage="None"):
        super(Tiles,self).__init__()
        #Heading Widget
        self.heading = QLabel('<b>%s</b>'%title)
        #SubHeading Widget with link to open in browser
        self.subHeading = QLabel('{}<a href="{}">...more</a>'.format(description,url))
        self.subHeading.setOpenExternalLinks(True)
        #Image Widget with article
        try:
            data = urllib.request.urlopen(urlImage).read()
        except:
            data = urllib.request.urlopen("https://ibb.co/XY30sjs").read()
        self.image = QImage()
        self.image.loadFromData(data)
        self.imageLabel = QLabel("image")
        self.imageLabel.setPixmap(QPixmap(self.image).scaled(64,64,Qt.KeepAspectRatio))
        self.tileLayout = QGridLayout()
        self.tileLayout.addWidget(self.heading,1,0)
        self.tileLayout.addWidget(self.imageLabel,1,1)
        self.tileLayout.addWidget(self.subHeading,2,0) 
开发者ID:ugroot,项目名称:GROOT,代码行数:22,代码来源:newsWindow.py

示例4: paintEvent

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def paintEvent(self, event):
        ancho, altura = self.width(), self.height()
        icono = self.icono.scaled(ancho, altura, Qt.KeepAspectRatio, Qt.SmoothTransformation)

        pintor = QPainter()
        
        pintor.begin(self)
        pintor.setRenderHint(QPainter.Antialiasing, True)
        pintor.setPen(Qt.NoPen)
        pintor.drawPixmap(0, 0, icono, 0, 0, 0, 0)
        pintor.setPen(Qt.white)
        pintor.drawText(event.rect(), Qt.AlignCenter, self.etiqueta)
        pintor.setPen(Qt.NoPen)
        pintor.setBrush(self.opacidad)
        pintor.drawEllipse(0, 0, ancho, altura)
        pintor.end()

        self.setMask(icono.mask()) 
开发者ID:andresnino,项目名称:PyQt5,代码行数:20,代码来源:botonCircular.py

示例5: initUI

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def initUI(self):
        label = QLabel(self)
        label.setPixmap(QPixmap("Imagenes/siacle.jpg").scaled(450, 450, Qt.KeepAspectRatio,
                                                              Qt.SmoothTransformation))
        label.move(0, 0)

        botonCerrar = QPushButton("Cerrar", self)
        botonCerrar.setFixedSize(430, 32)
        botonCerrar.move(10, 457)

      # ========================= EVENTO =========================

        botonCerrar.clicked.connect(self.close)


# ========================= CLASE Acerca =========================== 
开发者ID:andresnino,项目名称:PyQt5,代码行数:18,代码来源:siacle.py

示例6: initUI

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def initUI(self):

      # ==================== WIDGET QLABEL =======================
        
        self.labelImagen = QLabelClickable(self)
        self.labelImagen.setGeometry(15, 15, 118, 130)
        self.labelImagen.setToolTip("Imagen")
        self.labelImagen.setCursor(Qt.PointingHandCursor)

        self.labelImagen.setStyleSheet("QLabel {background-color: white; border: 1px solid "
                                       "#01DFD7; border-radius: 5px;}")

        self.pixmapImagen = QPixmap("Qt.png").scaled(112, 128, Qt.KeepAspectRatio,
                                                     Qt.SmoothTransformation)
        self.labelImagen.setPixmap(self.pixmapImagen)
        self.labelImagen.setAlignment(Qt.AlignCenter)

      # ===================== EVENTO QLABEL ======================

      # Llamar función al hacer clic o doble clic sobre el label
        self.labelImagen.clicked.connect(self.Clic)

  # ======================= FUNCIONES ============================ 
开发者ID:andresnino,项目名称:PyQt5,代码行数:25,代码来源:QLabel_clickable.py

示例7: _fit_in_view

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def _fit_in_view(view, rect, flags=Qt.IgnoreAspectRatio):
        if view.scene() is None or rect.isNull():
            return
        view.last_scene_roi = rect
        unity = view.transform().mapRect(QRectF(0, 0, 1, 1))
        view.scale(1 / unity.width(), 1 / unity.height())
        view_rect = view.viewport().rect()
        scene_rect = view.transform().mapRect(rect)
        xratio = view_rect.width() / scene_rect.width()
        yratio = view_rect.height() / scene_rect.height()
        if flags == Qt.KeepAspectRatio:
            xratio = yratio = min(xratio, yratio)
        elif flags == Qt.KeepAspectRatioByExpanding:
            xratio = yratio = max(xratio, yratio)
        view.scale(xratio, yratio)
        view.centerOn(rect.center())

    # name must match because we're overriding QMainWindow method 
开发者ID:andrewzwicky,项目名称:PUBGIS,代码行数:20,代码来源:gui.py

示例8: paint

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def paint(self, painter, option, index):
        column = index.column()
        if column == 1:
            pixmap = None
            status = index.data(Qt.UserRole)
            if status == MagicFolderChecker.LOADING:
                self.waiting_movie.setPaused(False)
                pixmap = self.waiting_movie.currentPixmap().scaled(
                    20, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation
                )
            elif status in (
                MagicFolderChecker.SYNCING,
                MagicFolderChecker.SCANNING,
            ):
                self.sync_movie.setPaused(False)
                pixmap = self.sync_movie.currentPixmap().scaled(
                    20, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation
                )
            if pixmap:
                point = option.rect.topLeft()
                painter.drawPixmap(QPoint(point.x(), point.y() + 5), pixmap)
                option.rect = option.rect.translated(pixmap.width(), 0)
        super(Delegate, self).paint(painter, option, index) 
开发者ID:gridsync,项目名称:gridsync,代码行数:25,代码来源:view.py

示例9: updateImage

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def updateImage(self, opencv_rgb_image):

        self.cv_img_rgb = opencv_rgb_image

        height, width, channel = self.cv_img_rgb.shape
        bytesPerLine = 3 * width
        self.q_image = QImage(self.cv_img_rgb.data, width,
                              height, bytesPerLine, QImage.Format_RGB888)
        # self.QPixmap=QPixmap.fromImage(self.q_image)
        # scaredPixmap = self.QPixmap.scaled(self,self.frame_lbl.frameSize, aspectRatioMode=Qt.IgnoreAspectRatio)
        self.frame_lbl.setPixmap(QPixmap.fromImage(self.q_image).scaled(self.frame_lbl.size(), aspectRatioMode=Qt.KeepAspectRatio)) 
开发者ID:anonymouslycn,项目名称:bjtu_BinocularCameraRecord,代码行数:13,代码来源:ImageCvQtContainer.py

示例10: reset_view

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def reset_view(self):
        # The SceneRect controls how far you can pan, make it larger than
        # just the bounding box so middle-click panning works
        panning_rect = QRectF(self.scene_bounding_rect)
        panning_rect_center = panning_rect.center()
        panning_rect_size = max(panning_rect.width(), panning_rect.height())*3
        panning_rect.setSize(QSizeF(panning_rect_size, panning_rect_size))
        panning_rect.moveCenter(panning_rect_center)
        self.setSceneRect(panning_rect)
        self.fitInView(self.scene_bounding_rect, Qt.KeepAspectRatio)
        self.zoom_view(0.8)

        self.update_grid() 
开发者ID:amccaugh,项目名称:phidl,代码行数:15,代码来源:quickplotter.py

示例11: update_preview

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def update_preview(self):
        if not self._preview_pixmap:
            return

        scaled = self._preview_pixmap.scaled(
            self._ui.lblPreview.width(),
            self._ui.lblPreview.height(),
            Qt.KeepAspectRatio,
            Qt.SmoothTransformation,
        )
        self._ui.lblPreview.setPixmap(scaled) 
开发者ID:zyantific,项目名称:IDASkins,代码行数:13,代码来源:themeselector.py

示例12: run

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def run(self):
        cap = cv2.VideoCapture(0)
        fps_update_cnt = 0
        fps_update_num = 10
        while True:
            display_time = time.time()
            ret, x_np = cap.read()
            x_np = cv2.cvtColor(x_np, cv2.COLOR_BGR2RGB)

            y_np, inference_time = self.transfer(x_np)

            x_qt = QImage(x_np.data, x_np.shape[1], x_np.shape[0], QImage.Format_RGB888)
            x_qt = QPixmap.fromImage(x_qt)
            x_qt = x_qt.scaled(self.video_width, self.video_height, Qt.KeepAspectRatio)

            y_qt = QImage(y_np.data, y_np.shape[1], y_np.shape[0], QImage.Format_RGB888)
            y_qt = QPixmap.fromImage(y_qt)
            y_qt = y_qt.scaled(self.video_width, self.video_height, Qt.KeepAspectRatio)

            self.change_pixmap_x.emit(x_qt)
            self.change_pixmap_y.emit(y_qt)

            fps_update_cnt = (fps_update_cnt + 1) % fps_update_num
            if fps_update_cnt == 0:
                self.change_pixmap_inf.emit('    Infrence FPS: {0:.2f}'.format(
                    1 / inference_time if inference_time is not None else 0))
                display_time = time.time() - display_time
                self.change_pixmap_dis.emit('    Display FPS: {0:.2f}'.format(1 / display_time)) 
开发者ID:changgyhub,项目名称:reconet,代码行数:30,代码来源:run.py

示例13: _draw_pixmap

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def _draw_pixmap(self, source, selected, synced):
        color = QColor(0x33, 0x33, 0x33) if selected else QColor(0x99, 0x99, 0x99)
        p = Pixmap(source)
        if p.isNull():
            return
        p = Pixmap(p.scaled(120, 120, Qt.KeepAspectRatio))
        p.replace_color(QColor(0, 0, 0), color)
        painter = QPainter(p)
        if synced:
            painter.drawPixmap(p.width() - 90, 0, 100, 100, IconTableItem.SYNCED_ICON)
        else:
            painter.drawPixmap(p.width() - 90, 0, 100, 100, IconTableItem.UNSYNCED_ICON)
        painter.end()
        return p 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:16,代码来源:file_items.py

示例14: seleccionarImagen

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def seleccionarImagen(self):
        imagen, extension = QFileDialog.getOpenFileName(self, "Seleccionar imagen", getcwd(),
                                                        "Archivos de imagen (*.png *.jpg)",
                                                        options=QFileDialog.Options())
          
        if imagen:
            # Adaptar imagen
            pixmapImagen = QPixmap(imagen).scaled(166, 178, Qt.KeepAspectRatio,
                                                  Qt.SmoothTransformation)

            # Mostrar imagen
            self.labelImagen.setPixmap(pixmapImagen) 
开发者ID:andresnino,项目名称:PyQt5,代码行数:14,代码来源:guardarImagen.py

示例15: initUI

# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import KeepAspectRatio [as 别名]
def initUI(self):

      # ===================== WIDGET QLABEL ======================

        label = QLabel(self)
        label.setGeometry(20, 20, 100, 100)
        label.setPixmap(QPixmap(":imagenes/Python.png").scaled(100, 100, Qt.KeepAspectRatio,
                                                               Qt.SmoothTransformation))


# ================================================================ 
开发者ID:andresnino,项目名称:PyQt5,代码行数:13,代码来源:incrustarImagenes.py


注:本文中的PyQt5.QtCore.Qt.KeepAspectRatio方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。