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


Python QSlider.show方法代码示例

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


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

示例1: MultiPageTIFFViewerQt

# 需要导入模块: from PyQt5.QtWidgets import QSlider [as 别名]
# 或者: from PyQt5.QtWidgets.QSlider import show [as 别名]
class MultiPageTIFFViewerQt(QWidget):
    """ Multi-page TIFF image stack viewer using tiffcapture (https://github.com/cdw/TiffCapture).

    Uses ImageViewerQt (https://github.com/marcel-goldschen-ohm/ImageViewerQt) to display the stack frames
    and handle mouse interaction (pan, zoom, click signals).

    Uses qimage2ndarray (https://github.com/hmeine/qimage2ndarray) to convert the format of stack frames
    from NumPy ndarray to QImage as requried by ImageViewerQt.

    Frame traversal via a slider and arrow buttons.
    """
    frameChanged = pyqtSignal([], [int])

    def __init__(self):
        QWidget.__init__(self)

        # Handle to the image stack tiffcapture object.
        self._tiffCaptureHandle = None
        self.currentFrameIndex = None

        # Image frame viewer.
        self.viewer = ImageViewerQt()

        # Slider and arrow buttons for frame traversal.
        self.frameSlider = QSlider(Qt.Horizontal)
        self.prevFrameButton = QPushButton("<")
        self.nextFrameButton = QPushButton(">")
        self.currentFrameLabel = QLabel()

        self.prevFrameButton.clicked.connect(self.prevFrame)
        self.nextFrameButton.clicked.connect(self.nextFrame)
        self.frameSlider.valueChanged.connect(self.showFrame)

        # Layout.
        grid = QGridLayout(self)
        grid.addWidget(self.currentFrameLabel, 0, 0, 1, 3)
        grid.addWidget(self.viewer, 1, 0, 1, 3)
        grid.addWidget(self.prevFrameButton, 2, 0)
        grid.addWidget(self.frameSlider, 2, 1)
        grid.addWidget(self.nextFrameButton, 2, 2)
        grid.setContentsMargins(2, 2, 2, 2)
        grid.setSpacing(0)

    def hasImageStack(self):
        """ Return whether or not an image stack is currently loaded.
        """
        return self._tiffCaptureHandle is not None

    def clearImageStack(self):
        """ Clear the current image stack if it exists.
        """
        if self._tiffCaptureHandle is not None:
            self.viewer.clearImage()
            self._tiffCaptureHandle = None

    def setImageStack(self, tiffCaptureHandle):
        """ Set the scene's current TIFF image stack to the input TiffCapture object.
        Raises a RuntimeError if the input tiffCaptureHandle has type other than TiffCapture.
        :type tiffCaptureHandle: TiffCapture
        """
        if type(tiffCaptureHandle) is not tiffcapture.TiffCapture:
            raise RuntimeError("MultiPageTIFFViewerQt.setImageStack: Argument must be a TiffCapture object.")
        self._tiffCaptureHandle = tiffCaptureHandle
        self.showFrame(0)

    def loadImageStackFromFile(self, fileName=''):
        """ Load an image stack from file.
        Without any arguments, loadImageStackFromFile() will popup a file dialog to choose the image file.
        With a fileName argument, loadImageStackFromFile(fileName) will attempt to load the specified file directly.
        """
        if len(fileName) == 0:
            if QT_VERSION_STR[0] == '4':
                fileName = QFileDialog.getOpenFileName(self, "Open TIFF stack file.")
            elif QT_VERSION_STR[0] == '5':
                fileName, dummy = QFileDialog.getOpenFileName(self, "Open TIFF stack file.")
        fileName = str(fileName)
        if len(fileName) and os.path.isfile(fileName):
            self._tiffCaptureHandle = tiffcapture.opentiff(fileName)
            self.showFrame(0)

    def numFrames(self):
        """ Return the number of image frames in the stack.
        """
        if self._tiffCaptureHandle is not None:
            # !!! tiffcapture has length=0 for a single page TIFF.
            # If our handle is valid, we'll assume we have at least one image.
            return max([1, self._tiffCaptureHandle.length])
        return 0

    def getAllFrames(self):
        """ Return the entire image stack as a NumPy ndarray.
        !!! This currently ONLY works for grayscale image stacks that can be represented as 3D arrays.
        !!! For large image stacks this can be time and memory hungry.
        """
        if self._tiffCaptureHandle is None:
            return None
        imageWidth = self._tiffCaptureHandle.shape[0]
        imageHeight = self._tiffCaptureHandle.shape[1]
        numFrames = self.numFrames()
        entireStackArray = np.empty((imageWidth, imageHeight, numFrames))
#.........这里部分代码省略.........
开发者ID:marcel-goldschen-ohm,项目名称:MultiPageTIFFViewerPyQt,代码行数:103,代码来源:MultiPageTIFFViewerQt.py

示例2: printValue

# 需要导入模块: from PyQt5.QtWidgets import QSlider [as 别名]
# 或者: from PyQt5.QtWidgets.QSlider import show [as 别名]
from PyQt5.QtWidgets import QApplication, QSlider


def printValue(value):
    print(value, slider.value())

app = QApplication(sys.argv)

slider = QSlider(orientation=Qt.Horizontal)
#slider = QSlider(orientation=Qt.Vertical)

slider.setMinimum(-15)
slider.setMaximum(15)

slider.setTickPosition(QSlider.TicksBelow)
slider.setTickInterval(5)

slider.setValue(5)   # Initial value

slider.valueChanged.connect(printValue)

slider.show()

# The mainloop of the application. The event handling starts from this point.
# The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.
exit_code = app.exec_()

# The sys.exit() method ensures a clean exit.
# The environment will be informed, how the application ended.
sys.exit(exit_code)
开发者ID:jeremiedecock,项目名称:snippets,代码行数:32,代码来源:widget_QSlider.py


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